Here you can find the source of toISO8601()
Date.prototype.toISO8601 = function() { //ex. "2001-02-03T04:05:06+09:00" var s = [// w w w.j av a2s. c o m this.getFullYear() , Date.padZero(this.getMonth() + 1) , Date.padZero(this.getDate()) ].join("-") + "T"; s += this.getTimeString(); s += this.getTimezoneOffsetString(true); return s; };
Date.prototype.toDateTimeFormat = function() { var year = this.getFullYear().toString(); var month = (this.getMonth() + 1).toString(); var day = this.getDate().toString(); var hour = this.getHours().toString(); var minute = this.getMinutes().toString(); var second = this.getSeconds().toString(); return year + '-' + (month[1] ? month : '0'+month[0]) + '-'+ (day[1] ? day : '0'+day[0]) + ' ' + (hour[1] ? hour : '0'+hour[0]) + ':' + (minute[1] ? minute : '0'+minute[0]) + ':' + (second[1] ? second : '0'+second[0]);
Date.prototype.toEndTimeInputValue = (function() { var local = new Date(this); local.setMinutes(this.getMinutes() - this.getTimezoneOffset() + 60); return local.toJSON().slice(11,13) + ":00:00"; });
Date.prototype.toFixedDate = function(){ var months = [ "January", "February", "March", "April", "May", "June", "Sol", "July", "August", "September", "October", "November", "December" ] var daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", ...
Date.prototype.toFormat = function (format) { format = format.replace(/H/, this.getHours()); format = format.replace(/m/, this.getMinutes()); format = format.replace(/s/, this.getSeconds()); return format; };
Date.prototype.toISO8601 = function() { function pad(n) { return n < 10 ? '0' + n : n; return this.getUTCFullYear() + '-' + pad(this.getUTCMonth() + 1) + '-' + pad(this.getUTCDate()) + 'T' + pad(this.getUTCHours()) + ':' + pad(this.getUTCMinutes()) + ':' + pad(this.getUTCSeconds()) + 'Z'; };
Date.prototype.toISO8601 = function (key) { function f(n) { return n < 10 ? '0' + n : n; function f2(n) { if(n < 10) return '00' + n; return n < 100 ? '0' + n : n; return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + '.' + f2(this.getUTCMilliseconds()) + '-0000' : null; };
Date.prototype.toInputFormat = function() { var yyyy = this.getFullYear().toString(); var mm = (this.getMonth()+1).toString(); var dd = this.getDate().toString(); return yyyy +'-'+ (mm[1]?mm:"0"+mm[0]) +'-'+ (dd[1]?dd:"0"+dd[0]); };
Date.prototype.toLocalTime = function() { const newDate = new Date(this.getTime()+this.getTimezoneOffset()*60*1000); let offset = this.getTimezoneOffset() / 60; const hours = this.getHours(); if (this.dst()) offset--; newDate.setHours(hours - offset); return newDate; };
'use strict'; Date.prototype.toLocaleFormat = Date.prototype.toLocaleFormat || function (pattern) { return pattern.replace(/%Y/g, this.getFullYear()).replace(/%m/g, (this.getMonth() + 1)).replace(/%d/g, this.getDate()); };