js 时间
2017-07-25 本文已影响0人
eyuxiog
1.
letdate =newDate();
letresult = date.toISOString().replace(/(.*)T([\d:]+).*/,'$1 $2');
document.write(result);
2.
var date = new Date();
var result = date.toLocaleString('zh-CN', { hour12: false })
.replace(/\//g, '-').replace(/\b\d\b/g, '0$&');
document.write(result);
3
functiondateFormat(formatStr, fdate){
varfTime, fStr ='ymdhis';
if(!formatStr)
formatStr="y-m-d h:i:s";
if(fdate)
fTime =newDate(fdate);
else
fTime =newDate();
varformatArr = [
fTime.getFullYear().toString(),
(fTime.getMonth()+1).toString(),
fTime.getDate().toString(),
fTime.getHours().toString(),
fTime.getMinutes().toString(),
fTime.getSeconds().toString()
];
for(vari=0; i
formatStr = formatStr.replace(fStr.charAt(i), formatArr[i]);
}
returnformatStr;
}
//调用js
dateFormat('y-m-d',newDate());