我使用此代码导出当前工作日的日期
var arr =[];
var curr = new Date();
var first = curr.getDate() - curr.getDay();
for (var i = 1; i < 6; i++) {
var next = new Date(curr.getTime());
next.setDate(first+1 );
arr.push(next.toString());
}
但输出看起来像数组中的 Mon Nov 09 2015 01:43:57 GMT-0800 (Pacific Standard Time)
["Mon Nov 09 2015 01:43:57 GMT-0800 (Pacific Standard Time)", "Mon Nov 09 2015 01:43:57 GMT-0800 (Pacific Standard Time)", "Mon Nov 09 2015 01:43:57 GMT-0800 (Pacific Standard Time)", "Mon Nov 09 2015 01:43:57 GMT-0800 (Pacific Standard Time)", "Mon Nov 09 2015 01:43:57 GMT-0800 (Pacific Standard Time)"]
您能否告诉我如何格式化 date() 以仅获取
2015 年 11 月 9 日星期一
并删除 01:43:57 GMT-0800(太平洋标准时间)
?
谢谢
最佳答案
您可以使用toDateString() Date 对象上的方法。
arr.push(next.toDateString());
关于javascript - 如何格式化 JavaScript 长字符串日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33647971/