Here you can find the source of prettyDate(time)
// Takes an ISO time and returns a string representing how // long ago the date represents. function prettyDate(time) { var date = new Date().setISO8601(time || ""); console.log('date: ' + date); var diff = (((new Date()).getTime() - date.getTime()) / 1000); console.log('diff: ' + diff); var day_diff = Math.floor(diff / 86400); console.log('daydiff: ' + day_diff); if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) { console.log('some shit went bad'); return;/*from w w w .j av a 2s .com*/ } return day_diff == 0 && ( diff < 60 && "just now" || diff < 120 && "1 minute ago" || diff < 3600 && Math.floor(diff / 60) + " minutes ago" || diff < 7200 && "1 hour ago" || diff < 86400 && Math.floor(diff / 3600) + " hours ago") || day_diff == 1 && "Yesterday" || day_diff < 7 && day_diff + " days ago" || day_diff < 31 && Math.ceil(day_diff / 7) + " weeks ago"; }
Date.prototype.getTimeShift = function() { return this.getTimezoneOffset() < this.stdTimezoneOffset()?3:2; };
getQueryString = function (field, url) { var href = url || window.location.href; var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i'); var string = reg.exec(href); return string ? string[1] : null; }; Date.prototype.getUnixTime = function () { return this.getTime() / 1000 | 0 }; ...
Date.prototype.halfHoursUntil = function(otherTime) { var hour = new Date(this); var numberOfHalfHours = 0; while (hour < otherTime) { numberOfHalfHours++; hour.addHalfHour(); return numberOfHalfHours; }; ...
Date.prototype.onlyTime = function () { return this.toTimeString().split(" ")[0]; };
Date.prototype.p8DeDate = function(time) { var d = this; function pad(n) { return n < 10 ? '0' + n : n; function pad3(n) { if(n < 10) { return '00' + n; } else if(n < 100) { ...
Date.prototype.setTimeToNow = function () var n = Date.relativeTo || new Date(); this.setHours(n.getHours()); this.setMinutes(n.getMinutes()); this.setSeconds(n.getSeconds()); this.setMilliseconds(n.getMilliseconds()); return this;
Date.prototype.time = function () { return this.getHours().zfill(2) + ":" + this.getMinutes().zfill(2) + ":" + this.getSeconds().zfill(2); };
Date.prototype.time = function(){ var hours = this.getHours(); if (hours === 0 || hours === 24) hours = 12; if (hours > 12) hours -= 12; var minutes = this.getMinutes(); if (minutes < 10) minutes = "0" + minutes; var ampm = this.getHours() >= 12 ? "pm" : "am"; return "" + hours + ":" + minutes + ampm;
Date.prototype.time24 = function() var hours = "" + this.getHours(); var minutes = "" + this.getMinutes(); var seconds = "" + this.getSeconds(); if(hours.length < 2) hours = "0"+hours; if(minutes.length < 2) minutes = "0"+minutes; ...