我需要日期以这种格式 2014-11-04 显示为“yy mm dd”
目前,我的脚本仍然显示我 2014 年 11 月 4 日星期二 00:00:00 GMT+0200(埃及标准时间)
$(document).ready(function() {
var userDate = '04.11.2014';
from = userDate.split(".");
f = new Date(from[2], from[1] - 1, from[0]);
console.log(f);
});
最佳答案
您可以使用日期对象的方法构造它
var date = new Date(userDate),
yr = date.getFullYear(),
month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(),
day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
newDate = yr + '-' + month + '-' + day;
console.log(newDate);
关于javascript - 在jquery中转换日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26549773/