Skip to content

Commit 2769964

Browse files
#14 - Java
1 parent b485df6 commit 2769964

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import java.time.LocalDateTime;
2+
import java.time.Period;
3+
import java.time.format.DateTimeFormatter;
4+
5+
/**
6+
* #14 FECHAS
7+
*
8+
* @author martinbohorquez
9+
*/
10+
public class martinbohorquez {
11+
12+
public static void main(String[] args) {
13+
LocalDateTime now = LocalDateTime.now();
14+
LocalDateTime birthDate = LocalDateTime.of(1994, 9, 26,
15+
18, 30, 45);
16+
System.out.printf("La fecha actual es: %s%n", now);
17+
System.out.printf("La fecha de nacimiento es: %s%n", birthDate);
18+
19+
System.out.printf("La edad es: %s%n", Period.between(birthDate.toLocalDate(),
20+
now.toLocalDate()));
21+
System.out.printf("La edad es: %s%n", Period.between(birthDate.toLocalDate(),
22+
now.toLocalDate()).getYears());
23+
System.out.printf("Los meses son: %s%n", Period.between(birthDate.toLocalDate(),
24+
now.toLocalDate()).getMonths());
25+
System.out.printf("Los días son: %s%n", Period.between(birthDate.toLocalDate(),
26+
now.toLocalDate()).getDays());
27+
28+
/*
29+
* DIFICULTAD EXTRA
30+
*/
31+
// Día, mes y año.
32+
DateTimeFormatter f = DateTimeFormatter.ofPattern("dd/MM/yyyy");
33+
System.out.printf("La fecha de nacimiento (Día, mes y año) es: %s%n",
34+
birthDate.toLocalDate().format(f));
35+
// Hora, minuto y segundo.
36+
f = DateTimeFormatter.ofPattern("HH:mm:ss");
37+
System.out.printf("La hora de nacimiento (Hora, mínuto y segundo) es: %s%n",
38+
birthDate.toLocalTime().format(f));
39+
// Día del año.
40+
System.out.printf("La día del año de la fecha nacimiento es: %s%n",
41+
birthDate.getDayOfYear());
42+
// Día del mes.
43+
System.out.printf("El día del mes de la fecha nacimiento es: %s%n",
44+
birthDate.getDayOfMonth());
45+
// Día de la semana.
46+
System.out.printf("El día de la semana de la fecha de nacimiento (Día, mes y año) es: %s%n",
47+
birthDate.getDayOfWeek().getValue());
48+
// Nombre del mes.
49+
System.out.printf("El nombre del mes de la fecha nacimiento es: %s%n",
50+
birthDate.getMonth().name());
51+
// Nombre del día de la semana.
52+
System.out.printf("El nombre del día de la semana de la fecha de nacimiento es: %s%n",
53+
birthDate.getDayOfWeek().name());
54+
55+
f = DateTimeFormatter.ofPattern("EE MMM dd HH:mm:ss yyyy");
56+
57+
System.out.printf("La fecha de nacimiento (Día, mes y año) es: %s%n",
58+
birthDate.format(f).toUpperCase());
59+
}
60+
}

0 commit comments

Comments
 (0)