-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6646 from 7R0N1X/main
#14 - JavaScript
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const currentDate = new Date(); | ||
console.log(currentDate); | ||
|
||
const dateOfBirth = new Date(1999, 7, 30, 5, 51, 30) | ||
console.log(dateOfBirth); | ||
|
||
function calculateElapsedYears(date1, date2) { | ||
return date1.getFullYear() - date2.getFullYear(); | ||
} | ||
|
||
console.log(`De ${dateOfBirth.getFullYear()} a ${currentDate.getFullYear()} han transcurrido ${calculateElapsedYears(currentDate, dateOfBirth)} años.`); | ||
|
||
const days = ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"]; | ||
const months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]; | ||
|
||
function formatDate(date) { | ||
const dayMonthYear = `${days[date.getDay()]} ${date.getDate()} de ${months[date.getMonth()]} de ${date.getFullYear()}` | ||
const hourMinuteSecond = `Hora: ${date.getHours()} Minuto: ${date.getMinutes()} Segundo: ${date.getSeconds()}` | ||
const dayOfYear = `Día del año: ${date.getDate()}` | ||
const dayOfWeek = `Día de la semana: ${days[date.getDay()]}` | ||
const nameOfMonth = `Mes: ${months[date.getMonth()]}` | ||
|
||
return { | ||
dayMonthYear, | ||
hourMinuteSecond, | ||
dayOfYear, | ||
dayOfWeek, | ||
nameOfMonth | ||
} | ||
} | ||
|
||
const data = formatDate(dateOfBirth); | ||
|
||
for(const value in data){ | ||
console.log(data[value]); | ||
} |