Skip to content

Commit

Permalink
Merge pull request #6646 from 7R0N1X/main
Browse files Browse the repository at this point in the history
#14 - JavaScript
  • Loading branch information
Roswell468 authored Oct 19, 2024
2 parents 761ed3b + fa59b56 commit 462ad79
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Roadmap/14 - FECHAS/javascript/7R0N1X.js
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]);
}

0 comments on commit 462ad79

Please sign in to comment.