web页面日期格式化插件

 1 (function ($) {
2 var FormatDateTime = function FormatDateTime() { };
3 $.FormatDateTime = function (obj, IsMi) {
4 var correcttime1 = eval('( new ' + obj.replace(new RegExp("\/", "gm"), "") + ')');
5 var myDate = correcttime1;
6 var year = myDate.getFullYear();
7 var month = ("0" + (myDate.getMonth() + 1)).slice(-2);
8 var day = ("0" + myDate.getDate()).slice(-2);
9 var h = ("0" + myDate.getHours()).slice(-2);
10 var m = ("0" + myDate.getMinutes()).slice(-2);
11 var s = ("0" + myDate.getSeconds()).slice(-2);
12 var mi = ("00" + myDate.getMilliseconds()).slice(-3);
13 if (IsMi == true) {
14 return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
15 }
16 else {
17 return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s + " " + mi;
18 }
19
20 }
21 })(jQuery);

 

使用方法:

$.FormatDateTime(item.ControlEndTime, false)

//item.ControlEndTime:后台返回的日期
//
false:布尔型,是否返回毫秒



你可能感兴趣的:(日期格式化)