Created
January 1, 2017 17:47
-
-
Save DanyelMorales/5260a3aec32db07a8b60e6ec82b77edd to your computer and use it in GitHub Desktop.
Timestamp algorithm based on UNIX TIMESTAMP
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
/** | |
* TIMESTAMP Algorithm. | |
* @author Daniel Vera Morales | |
* | |
* WARNING: This script is for demonstration and educational purpose, it is not a stable version. | |
*/ | |
// Testit using: http://www.unixtimestamp.com/index.php | |
// Explanation taken from: http://www.devshed.com/c/a/administration/unix-time-format-demystified/ | |
var yearFrom = 1970; | |
var yearTo=2017; // change | |
var monthFrom=01; | |
var monthTo=01; // change | |
var dayFrom=01; | |
var dayTo=02; // change | |
var hour = 21; | |
var minute = 30; | |
var seconds = 21; | |
// Algolas | |
var yearLeap = parseInt((yearTo - yearFrom)/4); | |
// ACUMULAO de dias en años | |
var yearTimeStamp = ((yearTo - yearFrom) * 365 ) + yearLeap; | |
// ACUMULAO de dias en meses | |
// variara segun la cantidad de dias en febrero y si es año biciesto, así como el número de dias de cada mes | |
// por ahora esta bien pero no es correcto el timestamp | |
var daysInMonths = [31,29,31,30,30,30,30,30,30,30,30,31]; | |
var monthsToAdd = (monthTo - monthFrom) - 1; | |
var calculatedDays = 0; | |
for(var i = 1; i < monthsToAdd; i++ ) | |
{ | |
calculatedDays += daysInMonths[i]; | |
} | |
// Agregando los dias de los años a los dias en meses | |
var monthTimeStamp = (calculatedDays + dayTo); | |
// date timestamp | |
var datetimestamp = (monthTimeStamp + yearTimeStamp) * 24 * 60 * 60; | |
// time timestamp | |
var hourStamp = 21 * 60 * 60; | |
var minuteStamp = minute * 60; | |
var timeTiestamp = hourStamp + minuteStamp + seconds; | |
// timestamp | |
var timestamp = timeTiestamp + datetimestamp; | |
console.log(timestamp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment