Skip to content

Commit bb87120

Browse files
authored
Merge pull request mouredev#4818 from RaulDoezon/14-JavaScript
#14 - JavaScript
2 parents 0ccd29e + 588661c commit bb87120

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+
/*
2+
* EJERCICIO:
3+
* Crea dos variables utilizando los objetos fecha (date, o semejante) de tu lenguaje:
4+
* - Una primera que represente la fecha (día, mes, año, hora, minuto, segundo) actual.
5+
* - Una segunda que represente tu fecha de nacimiento (te puedes inventar la hora).
6+
* Calcula cuántos años han transcurrido entre ambas fechas.
7+
*
8+
* DIFICULTAD EXTRA (opcional):
9+
* Utilizando la fecha de tu cumpleaños, formatéala y muestra su resultado de
10+
* 10 maneras diferentes. Por ejemplo:
11+
* - Día, mes y año.
12+
* - Hora, minuto y segundo.
13+
* - Día de año.
14+
* - Día de la semana.
15+
* - Nombre del mes.
16+
* (lo que se te ocurra...)
17+
*/
18+
19+
console.log("+++++++++ EJERCICIO +++++++++");
20+
var today = new Date();
21+
var birthday = new Date(1992, 2, 31, 7, 30, 0, 999);
22+
var msPerYear = 24 * 60 * 60 * 365 * 1000;
23+
var years = (today.getTime() - birthday.getTime()) / msPerYear;
24+
25+
console.log(`Fecha actual: ${today}`);
26+
console.log(`Fecha de nacimiento: ${birthday}`);
27+
console.log(`Años transcurridos: ${years}`);
28+
29+
console.log("\n+++++++++ DIFICULTAD EXTRA +++++++++");
30+
console.log(`DÍA: ${birthday.getDate()}`);
31+
console.log(`MES: ${birthday.getMonth() + 1}`);
32+
console.log(`AÑO: ${birthday.getFullYear()}`);
33+
console.log(`DÍA DE LA SEMANA: ${birthday.getDay()}`);
34+
console.log(`HORAS: ${birthday.getHours()}`);
35+
console.log(`MINUTOS: ${birthday.getMinutes()}`);
36+
console.log(`SEGUNDOS: ${birthday.getSeconds()}`);
37+
console.log(`MILISEGUNDOS: ${birthday.getMilliseconds()}`);
38+
console.log(`FECHA: ${birthday.getDate()}/${birthday.getMonth() + 1}/${birthday.getFullYear()}`);
39+
console.log(`HORA: ${birthday.getHours()}:${birthday.getMinutes()}:${birthday.getSeconds()}`);

0 commit comments

Comments
 (0)