Skip to content

Commit e055886

Browse files
committed
#14 - JavaScript
1 parent 0cec9bd commit e055886

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const currentDate = new Date();
2+
console.log(currentDate);
3+
4+
const dateOfBirth = new Date(1999, 7, 30, 5, 51, 30)
5+
console.log(dateOfBirth);
6+
7+
function calculateElapsedYears(date1, date2) {
8+
return date1.getFullYear() - date2.getFullYear();
9+
}
10+
11+
console.log(`De ${dateOfBirth.getFullYear()} a ${currentDate.getFullYear()} han transcurrido ${calculateElapsedYears(currentDate, dateOfBirth)} años.`);
12+
13+
const days = ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"];
14+
const months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
15+
16+
function formatDate(date) {
17+
const dayMonthYear = `${days[date.getDay()]} ${date.getDate()} de ${months[date.getMonth()]} de ${date.getFullYear()}`
18+
const hourMinuteSecond = `Hora: ${date.getHours()} Minuto: ${date.getMinutes()} Segundo: ${date.getSeconds()}`
19+
const dayOfYear = `Día del año: ${date.getDate()}`
20+
const dayOfWeek = `Día de la semana: ${days[date.getDay()]}`
21+
const nameOfMonth = `Mes: ${months[date.getMonth()]}`
22+
23+
return {
24+
dayMonthYear,
25+
hourMinuteSecond,
26+
dayOfYear,
27+
dayOfWeek,
28+
nameOfMonth
29+
}
30+
}
31+
32+
const data = formatDate(dateOfBirth);
33+
34+
for(const value in data){
35+
console.log(data[value]);
36+
}

0 commit comments

Comments
 (0)