Here you can find the source of timeStr()
/* CONSTANTS ****************************************************************/ var DAY_WIDTH = 100; var DAY_HEIGHT = 80; var SIDE_DELTA = 2; var DAY_HEADING = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]; var MONTH_NAMES = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]; Date.prototype.timeStr = function () { var hr = this.getHours(); var pm = false; if (hr > 12) {/*from ww w. j a va 2 s . c om*/ hr -= 12; pm = true; } else if (hr == 12) { pm = true; } else if (hr == 0) { hr = 12; } var min = this.getMinutes().toString(); if (min.length == 1) { min = "0".concat(min); } return hr + ":" + min + (pm ? "p" : "a"); }; /* ADDING METHODS TO Date ****************************************************/ Date.prototype.daysIn = function () { return (new Date(this.getFullYear(), this.getMonth()+1, 0)).getDate(); }; Date.prototype.getYearMonth = function () { return ((this.getFullYear())*12 + this.getMonth()); } Date.prototype.plusMonth = function () { if (this.getMonth() == 11) { return new Date(this.getFullYear()+1, 0, this.getDate(), this.getHours(), this.getMinutes(), this.getMilliseconds()); } else { return new Date(this.getFullYear(), this.getMonth()+1, this.getDate(), this.getHours(), this.getMinutes(), this.getMilliseconds()); } } Date.prototype.minusMonth = function () { if (this.getMonth() == 0) { return new Date(this.getFullYear()-1, 11, this.getDate(), this.getHours(), this.getMinutes(), this.getMilliseconds()); } else { return new Date(this.getFullYear(), this.getMonth()-1, this.getDate(), this.getHours(), this.getMinutes(), this.getMilliseconds()); } }
String.prototype.format = function(obj) { var args = arguments; var str = this; return str.replace(/\{[\w\d_-]+\}/g, function(part) { part = part.slice(1, -1); var index = parseInt(part, 10); if (isNaN(index)) { return obj[part]; } else { ...
"use strict"; Date.prototype.timeAgoInWords = function (relativeDate) { var delta; relativeDate = relativeDate || new Date(); delta = parseInt((relativeDate.getTime() - this) / 1000, 10); if (delta < 60) { return 'less than a minute ago'; } else if (delta < 120) { return 'about a minute ago'; ...
var timeFmt = function (aDate) { if (null == aDate) { return ""; else { return new Date(aDate).format("yyyy-MM-dd hh:mm:ss"); };
Date.prototype.timeSecond = function () { return ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
String.prototype.startsWith = function (str){ return this.indexOf(str) === 0; }; timeSince = function (date) { var seconds = Math.floor((new Date() - date) / 1000); var interval = Math.floor(seconds / 31536000); if (interval >= 1) { if(interval == 1){ return "about " + interval + " year ago"; ...
Date.prototype.timeToJSON = function() { return this.toLocaleTimeString().substring(0,5); };
Date.prototype.timeToMidnight = function() {
this.setHours(0);
this.setMinutes(0);
this.setMilliseconds(0);
};
function time_between_in_words(from_date, to_date) return format_milliseconds(Math.abs(from_date.getTime()-to_date.getTime())); function time_ago_in_words(date) return format_milliseconds(Math.abs(Date.now()-date.getTime())); function format_milliseconds(milsecs) ...
var chunks = [ [60 * 60 * 24 * 365, 'year'], [60 * 60 * 24 * 30, 'month'], [60 * 60 * 24 * 7, 'week'], [60 * 60 * 24, 'day'], [60 * 60, 'hour'], [60, 'minute'] ]; Date.prototype.time_since = function() { ...