Home > Web Front-end > JS Tutorial > body text

Web page date formatting plug-in based on jquery_jquery

WBOY
Release: 2016-05-16 17:59:26
Original
1270 people have browsed it
复制代码 代码如下:

(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:布尔型,是否返回毫秒
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!