Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created April 14, 2020 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidPeralvarez/443161e9c7bc43e156fb946f8756805d to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/443161e9c7bc43e156fb946f8756805d to your computer and use it in GitHub Desktop.
JavaScript - El objeto Date
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
/* Objetos Date */
var fechaActual = new Date();
console.log( fechaActual );
// fecha en milisegundos
console.log( fechaActual.getTime() );
// año
console.log( fechaActual.getFullYear() );
// mes 0-11
console.log( fechaActual.getMonth() );
// día del mes
console.log( fechaActual.getDate() );
// día de la semana 0 - 6 (domingo - sábado)
console.log( fechaActual.getDay() );
// hora, minutos
console.log( fechaActual.getHours(), fechaActual.getMinutes(), fechaActual.getSeconds(), fechaActual.getMilliseconds() );
var fechaMS = new Date( 1586858939315 );
console.log( fechaMS );
// year, month, day, hour, minutes, seconds, milliseconds
var fechaConcreta = new Date( 2060, 13, 25, 26, 30, 20, 60000 );
console.log( fechaConcreta );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment