/**
* 返回格式化日期字符串
* @param 日期对象
* @return yyyy-MM-dd
*/
$.formatDateStyle1 = function(myDate) {
var year = myDate.getFullYear();
var month = ("0" + (myDate.getMonth() + 1)).slice(-2);
var day = ("0" + myDate.getDate()).slice(-2);
return year + "-" + month + "-" + day;
};
/**
* 返回格式化日期字符串
* @param 日期对象
* @return hh-mm-ss
*/
$.formatDateStyle2 = function(myDate) {
var h = ("0" + myDate.getHours()).slice(-2);
var m = ("0" + myDate.getMinutes()).slice(-2);
var s = ("0" + myDate.getSeconds()).slice(-2);
return h + ":" + m + ":" + s;
};
/**
* 返回格式化日期字符串
* @param 日期对象
* @return yyyy-MM-dd hh-mm-ss
*/
$.formatDateStyle3 = function(myDate) {
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);
return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
};
$.formatDateStyle4 = function(myDate) {
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);
return year + "-" + month + "-" + day + " " + h + ":" + m;
};
$.FormatDateTime = function(obj, IsMi) {
var myDate = new Date(obj);
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;
}
};
js Date格式化
最新推荐文章于 2021-10-22 11:57:12 发布