mirror of
https://github.com/cq-panda/Vue.NetCore.git
synced 2026-10-21 00:38:23 +08:00
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
(function ($) {
|
|
Date.prototype.format = function (format) {
|
|
var o = {
|
|
"M+": this.getMonth() + 1, //month
|
|
"d+": this.getDate(), //day
|
|
"h+": this.getHours(), //hour
|
|
"m+": this.getMinutes(), //minute
|
|
"s+": this.getSeconds(), //second
|
|
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
|
|
"S": this.getMilliseconds() //millisecond
|
|
}
|
|
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
|
|
(this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
for (var k in o) if (new RegExp("(" + k + ")").test(format))
|
|
format = format.replace(RegExp.$1,
|
|
RegExp.$1.length == 1 ? o[k] :
|
|
("00" + o[k]).substr(("" + o[k]).length));
|
|
return format;
|
|
}
|
|
String.prototype.formatTime = function () {
|
|
return this.callFormat("yyyy-MM-dd hh:mm:ss");
|
|
}
|
|
String.prototype.formatDate = function (val) {
|
|
return this.callFormat("yyyy-MM-dd");
|
|
}
|
|
String.prototype.callFormat = function (_format) {
|
|
var _regex = /-?\d+/;
|
|
var datePart = _regex.exec(this);
|
|
if (!(datePart && datePart.length > 0)) {
|
|
return "";
|
|
}
|
|
var _newDate = new Date(parseInt(datePart[0]));
|
|
return _newDate.format(_format);
|
|
}
|
|
|
|
getNowFormatDate=function () {
|
|
var date = new Date();
|
|
var seperator1 = "-";
|
|
var seperator2 = ":";
|
|
var month = date.getMonth() + 1;
|
|
var strDate = date.getDate();
|
|
if (month >= 1 && month <= 9) {
|
|
month = "0" + month;
|
|
}
|
|
if (strDate >= 0 && strDate <= 9) {
|
|
strDate = "0" + strDate;
|
|
}
|
|
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
|
|
+ " " + date.getHours() + seperator2 + date.getMinutes()
|
|
+ seperator2 + date.getSeconds();
|
|
return currentdate;
|
|
}
|
|
|
|
})(jQuery) |