Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created June 2, 2015 17:47
Show Gist options
  • Save 1ambda/159131e7ba919bbb6bce to your computer and use it in GitHub Desktop.
Save 1ambda/159131e7ba919bbb6bce to your computer and use it in GitHub Desktop.
Time.js
// Syrup
this.formatDate = function(num){
var fom = "";
var iNum;
if(!isNaN(num)){
iNum = Number(num);
if(iNum < 10) { fom = "0" + iNum; }
else { fom = "" + iNum; }
return fom;
}
return num;
};
this.getLatencyId = function() {
var today = new Date();
var to_year = today.getFullYear();
var to_month = this.formatDate(today.getMonth() + 1);
var to_date = this.formatDate(today.getDate());
var to_hours = this.formatDate(today.getHours());
var to_minutes = this.formatDate(today.getMinutes());
var to_seconds = this.formatDate(today.getSeconds());
return [to_year, to_month, to_date, to_hours, to_minutes, to_seconds, today.getMilliseconds()].join("");
}
// Rake
timeStamp: function(date) {
var date_str = date.getFullYear().toString();
date_str += (((date.getMonth()+1)<10?'0':''))+(date.getMonth()+1).toString();
date_str += ((date.getDate()<10?'0':'') + date.getDate()).toString();
var hours = (date.getHours()<10?'0':'') + date.getHours()
date_str += hours.toString();
date_str += ((date.getMinutes()<10?'0':'') + date.getMinutes()).toString();
date_str += ((date.getSeconds()<10?'0':'') + date.getSeconds()).toString();
var milliseconds = date.getMilliseconds();
if(milliseconds < 10){
date_str += '00';
}else if(milliseconds <100){
date_str += '0';
}
date_str += milliseconds.toString();
return date_str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment