Skip to content

Commit eab7cdf

Browse files
authored
Merge pull request mouredev#2677 from Vecinacoo/SolucionEj14Java
#14 - java
2 parents 5efab41 + 061ca34 commit eab7cdf

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.time.Duration;
2+
import java.time.LocalDate;
3+
import java.time.LocalDateTime;
4+
import java.time.LocalTime;
5+
import java.time.temporal.ChronoUnit;
6+
7+
public class P14 {
8+
9+
public static void main(String[] args) {
10+
11+
// Mostrando agnos pasados desde la fecha de nacimiento hasta ahora
12+
LocalDateTime fechaAhora = LocalDateTime.of(LocalDate.now(), LocalTime.now());
13+
14+
LocalDateTime fechaNacimiento = LocalDateTime.of(LocalDate.of(2005, 10, 31), LocalTime.of(10, 30));
15+
16+
Duration duration = Duration.between(fechaNacimiento, fechaAhora);
17+
18+
long agnos = ChronoUnit.YEARS.between(LocalDateTime.now(), LocalDateTime.now().plus(duration));
19+
20+
System.out.println(agnos);
21+
22+
// OPCIONAL
23+
mostrandoFechaCumpleagnos(fechaNacimiento);
24+
25+
}
26+
27+
private static void mostrandoFechaCumpleagnos(LocalDateTime n) {
28+
29+
System.out.println(n.getDayOfMonth() + " " + n.getMonth() + n.getYear());
30+
31+
System.out.println(n.getHour() + ":" + n.getMinute() + ":" + n.getSecond());
32+
33+
System.out.println("Dia " + n.getDayOfYear() + " del agno");
34+
35+
System.out.println("Dia " + n.getDayOfWeek() + " de la semana");
36+
37+
}
38+
39+
}

0 commit comments

Comments
 (0)