Skip to content

Commit 47274d4

Browse files
committed
JavaScript
1 parent 2b2cdc4 commit 47274d4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
let fecha = new Date();
2+
console.log(fecha);
3+
4+
let miFecha = new Date(1990, 11, 8, 4, 11, 11);
5+
console.log(miFecha);
6+
7+
8+
function años (fecha, miFecha) {
9+
let tiempoEnMs = fecha - miFecha;
10+
let tiempoPasado = tiempoEnMs / (1000 * 60 * 60 * 24 * 365);
11+
tiempoPasado = Math.floor(tiempoPasado);
12+
return tiempoPasado;
13+
}
14+
15+
console.log(años(fecha, miFecha));
16+
17+
//EXTRA
18+
console.log("Día, mes y año:", miFecha.getDate(), "/" + (miFecha.getMonth() + 1), "/" + miFecha.getFullYear());
19+
console.log("Hora, minutos y segundos:", miFecha.getHours() + ":" + miFecha.getMinutes() + ":" + miFecha.getSeconds());
20+
console.log("Día de año:", Math.floor((miFecha - new Date(miFecha.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24)));
21+
let diaSemana = ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sábado"]
22+
console.log("Día de la semana:", diaSemana[miFecha.getDay()]);
23+
let nombreMes = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]
24+
console.log("Mes de año:" , nombreMes[miFecha.getMonth()])

0 commit comments

Comments
 (0)