1
+
2
+ import 'package:intl/intl.dart' ;
3
+
4
+ /*
5
+ * EJERCICIO:
6
+ * Crea dos variables utilizando los objetos fecha (date, o semejante) de tu lenguaje:
7
+ * - Una primera que represente la fecha (día, mes, año, hora, minuto, segundo) actual.
8
+ * - Una segunda que represente tu fecha de nacimiento (te puedes inventar la hora).
9
+ * Calcula cuántos años han transcurrido entre ambas fechas.
10
+ *
11
+ * DIFICULTAD EXTRA (opcional):
12
+ * Utilizando la fecha de tu cumpleaños, formatéala y muestra su resultado de
13
+ * 10 maneras diferentes. Por ejemplo:
14
+ * - Día, mes y año.
15
+ * - Hora, minuto y segundo.
16
+ * - Día de año.
17
+ * - Día de la semana.
18
+ * - Nombre del mes.
19
+ * (lo que se te ocurra...)
20
+ */
21
+
22
+
23
+ void main ()
24
+ {
25
+ DateTime date = DateTime .now ();
26
+ DateTime birthDay = DateTime (1991 , 9 , 14 , 1 , 0 , 0 );
27
+ DateFormat dateFormatter = DateFormat ('dd/MM/yyyy hh:mm' );
28
+ Duration dateDifference = date.difference (birthDay);
29
+
30
+ print ('Fecha actual: ' + dateFormatter.format (date));
31
+ print ('Cumple : ' + dateFormatter.format (birthDay));
32
+ print ('Transcurrido: ${(dateDifference .inDays / 365 ).floor ().toString ()} años' );
33
+
34
+ //Dificultad extra
35
+
36
+ DateFormat dateFormatter_ddMMyyyy = DateFormat ('dd/MM/yyyy' );
37
+ DateFormat dateFormatter_hhmmss = DateFormat ('hh:mm:ss' );
38
+ DateFormat dateFormatter_Completa = DateFormat ('EEEE, dd MMMM, yyyy' );
39
+ DateFormat dateFormatter_diaSemana = DateFormat ('EEEE' );
40
+ DateFormat dateFormatter_Mes = DateFormat ('MMMM' );
41
+
42
+ print ('Cumple : ' + dateFormatter_ddMMyyyy.format (birthDay));
43
+ print ('Cumple : ' + dateFormatter_hhmmss.format (birthDay));
44
+ print ('Cumple : ' + dateFormatter_Completa.format (birthDay));
45
+ print ('Cumple : ' + dateFormatter_diaSemana.format (birthDay));
46
+ print ('Cumple : ' + dateFormatter_Mes.format (birthDay));
47
+ }
0 commit comments