Skip to content

Commit a0ef4de

Browse files
authored
Merge pull request #95 from marcode24/2024-14-ts
✨ Add typescript solution challenge-14
2 parents 8285c5b + 855086f commit a0ef4de

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

2024/14-fechas/solution.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Crear una variable con la fecha actual
2+
const fechaActual: Date = new Date();
3+
4+
// Crear una variable con tu fecha de nacimiento (puedes modificar esta fecha)
5+
const fechaNacimiento: Date = new Date('2001-08-24T19:30:00');
6+
7+
// Calcular la diferencia en milisegundos
8+
const diferenciaTiempo: number = fechaActual.getTime() - fechaNacimiento.getTime();
9+
10+
// Convertir la diferencia en milisegundos a años
11+
const milisegundosPorAño: number = 1000 * 60 * 60 * 24 * 365.25; // Considerando años bisiestos
12+
const añosTranscurridos: number = Math.floor(diferenciaTiempo / milisegundosPorAño);
13+
14+
console.log(`Han transcurrido ${añosTranscurridos} años desde tu nacimiento.`);
15+
16+
// Formatear y mostrar la fecha de nacimiento de 10 maneras diferentes
17+
console.log(
18+
`1. Día, mes y año: ${fechaNacimiento.getDate()}/${
19+
fechaNacimiento.getMonth() + 1
20+
}/${fechaNacimiento.getFullYear()}`
21+
);
22+
console.log(
23+
`2. Hora, minuto y segundo: ${fechaNacimiento.getHours()}:${fechaNacimiento.getMinutes()}:${fechaNacimiento.getSeconds()}`
24+
);
25+
console.log(
26+
`3. Día del año: ${Math.ceil(
27+
(fechaNacimiento.getTime() - new Date(fechaNacimiento.getFullYear(), 0, 1).getTime())
28+
/ (1000 * 60 * 60 * 24)
29+
)}`
30+
);
31+
console.log(
32+
`4. Día de la semana: ${fechaNacimiento.toLocaleString('es-ES', {
33+
weekday: 'long',
34+
})}`
35+
);
36+
console.log(
37+
`5. Nombre del mes: ${fechaNacimiento.toLocaleString('es-ES', {
38+
month: 'long',
39+
})}`
40+
);
41+
console.log(`6. Año completo: ${fechaNacimiento.getFullYear()}`);
42+
console.log(`7. Mes (número): ${fechaNacimiento.getMonth() + 1}`);
43+
console.log(`8. Día (número): ${fechaNacimiento.getDate()}`);
44+
console.log(`9. Fecha ISO: ${fechaNacimiento.toISOString()}`);
45+
console.log(`10. Fecha local: ${fechaNacimiento.toLocaleDateString('es-ES')}`);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ npm run test 'year'/'folder-name'/solution.test.js
6363
| 11 | [Manejo de Ficheros](https://retosdeprogramacion.com/roadmap/) | 🟡 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/11-manejo-de-ficheros/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/11-manejo-de-ficheros/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/11-manejo-de-ficheros/solution.php) |
6464
| 12 | [Json y XML](https://retosdeprogramacion.com/roadmap/) | 🔴 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/12-json-y-xml/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/12-json-y-xml/solution.ts) <br /> [![PHP](https://img.shields.io/badge/PHP-777BB4?style=flat&logo=php&logoColor=white)](./2024/12-json-y-xml/solution.php) |
6565
| 13 | [Pruebas Unitarias](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/13-pruebas-unitarias/index.js) |
66-
| 14 | [Fechas](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/14-fechas/index.js) |
66+
| 14 | [Fechas](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/14-fechas/index.js) <br /> [![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)](./2024/14-fechas/solution.ts) |
6767
| 15 | [Asincronía](https://retosdeprogramacion.com/roadmap/) | 🔴 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/15-asincronia/index.js) |
6868
| 16 | [Expresiones Regulares](https://retosdeprogramacion.com/roadmap/) | 🟡 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/16-expresiones-regulares/index.js) |
6969
| 17 | [Iteraciones](https://retosdeprogramacion.com/roadmap/) | 🟢 | [![JavaScript](https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black)](./2024/17-iteraciones/index.js) |

0 commit comments

Comments
 (0)