例如:Wed Nov 14 2018 02:00:00 GMT+0800 (中国标准时间)
怎么将它转换成 2018/11/14 02:00:00 或是 2018-11/-14 02:00:00,date的原生方法没有吗?
用了一个toLocaleString()还分上午下午
1 回答
神不在的星期二
TA贡献1963条经验 获得超6个赞
为何要转换,你需要这样:
function getNowDate(){
var date = new Date(),
year = date.getFullYear(),
month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1,
day = date.getDay() < 10 ? '0' + date.getDay() : date.getDay(),
hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(); return year + '/' + month + '/' + day + ' ' + hour + ':' + minute + ':' + second;
}添加回答
举报
0/150
提交
取消
