UNPKG

ht_server

Version:

纯后台框架 http

69 lines (59 loc) 2.31 kB
// Date的函数扩展 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "W": this.getDay(), "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } Date.prototype.FormatForDb = function () { return this.Format("yyyy-MM-dd hh:mm:ss"); } Date.prototype.FormatForDb1 = function () { return this.Format("yyyyMMddhhmmss"); } Date.prototype.FormatForHours = function () { return this.Format("yyyy-MM-dd hh"); } Date.prototype.FormatForDay = function () { return this.Format("yyyy-MM-dd"); } Date.prototype.FormatForMonth = function () { return this.Format("yyyy-MM"); } Date.prototype.FormatForMin = function () { return this.Format("mm:ss"); } Date.prototype.getWeekString = function () { var weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']; return weeks[this.getDay()]; } Date.prototype.newDayWithDelta = function (delta) { var deltamm = delta * 24 * 60 * 60 * 1000; var day = new Date(); day.setTime(this.getTime() + deltamm); return day; } Date.prototype.newLastDay = function () { return this.newDayWithDelta(-1); } Date.prototype.newNextDay = function () { return this.newDayWithDelta(1); } // 自己的date - 传入的date Date.prototype.getDiffDay = function (day) { var d1 = new Date(this.getFullYear(), this.getMonth(), this.getDate()); var d2 = new Date(day.getFullYear(), day.getMonth(), day.getDate()); // console.log(this.getFullYear() + ', ' + this.getMonth() + ', ' + this.getDate()); // console.log(day.getFullYear() + ', ' + day.getMonth() + ', ' + day.getDate()); return (d1 - d2) / (24 * 60 * 60 * 1000); }