-
-
Save DavidPeralvarez/3a0b79403c675f2823325f96857f6ffd to your computer and use it in GitHub Desktop.
JavaScript - Trabajando con fechas
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Curso de Javascript</title> | |
</head> | |
<body> | |
<script src="scripts.js"></script> | |
</body> | |
</html> |
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
/* Objetos Date */ | |
// Tiempo en segundos que dura una tarea | |
// var inicio = new Date(); | |
// for ( var i = 0; i < 10000; i++ ) { | |
// console.log( 'Tarea' ); | |
// } | |
// var fin = new Date(), | |
// duracion = (fin.getTime() - inicio.getTime()) / 1000; | |
// console.log( duracion.toFixed(2) + ' segundos.' ); | |
var currentDate = new Date(); | |
console.log( currentDate ); | |
// sumar años | |
Date.prototype.sumYears = function( years ) { | |
this.setYear( this.getFullYear() + years ); | |
return this; | |
} | |
currentDate.sumYears( -5 ); | |
console.log( currentDate ); | |
// sumar meses | |
Date.prototype.sumMonths = function( months ) { | |
this.setMonth( this.getMonth() + months ); | |
return this; | |
} | |
currentDate.sumMonths( 2 ); | |
console.log( currentDate ); | |
// sumar días | |
Date.prototype.sumDays = function( days ) { | |
this.setDate( this.getDate() + days ); | |
return this; | |
} | |
currentDate.sumDays( 30 ); | |
console.log( currentDate ); | |
// sumar horas, minutos, segundos, milisegundos | |
// setHours, setMinutes, setSeconds, setMilliseconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment