基于jquery的web页面日期格式化插件
代码如下:
(function ($) {
var formatdatetime = function formatdatetime() { };
$.formatdatetime = function (obj, ismi) {
var correcttime1 = eval('( new ' + obj.replace(new regexp("\/", "gm"), "") + ')');
var mydate = correcttime1;
var year = mydate.getfullyear();
var month = ("0" + (mydate.getmonth() + 1)).slice(-2);
var day = ("0" + mydate.getdate()).slice(-2);
var h = ("0" + mydate.gethours()).slice(-2);
var m = ("0" + mydate.getminutes()).slice(-2);
var s = ("0" + mydate.getseconds()).slice(-2);
var mi = ("00" + mydate.getmilliseconds()).slice(-3);
if (ismi == true) {
return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
}
else {
return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s + " " + mi;
}
}
})(jquery);
使用方法:
代码如下:
$.formatdatetime(item.controlendtime, false)
//item.controlendtime:后台返回的日期
//false:布尔型,是否返回毫秒
上一篇: asp.net用三层实现多条件检索
下一篇: jsp的运行原理和基本语法