function dateTimeFormat(datetime, type) {
var myDate = new Date(datetime);
var reDateTime = "";
var myYear = myDate.getFullYear();
var myMonth = (myDate.getMonth() + 1) >= 10 ? (myDate.getMonth() + 1) : "0" + (myDate.getMonth() + 1);
var myDay = myDate.getDate() < 10 ? "0" + myDate.getDate() : myDate.getDate()
var myHours = myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours();
var myMin = myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes();
var mySenconds = myDate.getSeconds() < 10 ? "0" + myDate.getSeconds() : myDate.getSeconds();
if (type == "yyyy/mm/dd HH:MM:SS") {
reDateTime = myYear + "/" + myMonth + "/" + myDay + " " + myHours + ":" + myMin + ":" + mySenconds;
} else if (type == "yyyy-mm-dd HH:MM:SS") {
reDateTime = myYear + "-" + myMonth + "-" + myDay + " " + myHours + ":" + myMin + ":" + mySenconds;
} else if (type == "yyyy-mm-dd") {
reDateTime = myYear + "-" + myMonth + "-" + myDay;
} else if (type == "yyyy/mm/dd") {
reDateTime = myYear + "/" + myMonth + "/" + myDay;
} else if (type == "yyyy-mm-dd HH") {
reDateTime = myYear + "-" + myMonth + "-" + myDay + " " + myHours;
}
else if (type == "yymmdd") {
reDateTime = myYear.toString().substr(2, 2) + myMonth.toString() + myDay.toString();
}
else if (type == "HH:MM") {
reDateTime = myHours + ":" + myMin;
}
return reDateTime;
};
Jquery 时间格式化
最新推荐文章于 2024-03-09 15:44:43 发布