gpt4 book ai didi

javascript - 从当前日期减去 1 周 - javascript

转载 作者:行者123 更新时间:2023-11-29 16:14:06 25 4
gpt4 key购买 nike

这就是我获取当前日期的方式,dd-MMM-yyyy 格式。我如何减去 1 周。

    var m_names = new Array("JAN", "FEB", "MAR",
"APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
var current = curr_date + "-" + m_names[curr_month] + "-" + curr_year;

最佳答案

只需添加 d.setDate(d.getDate() - 7);在你的 var d = new Date(); 之后

 var m_names = new Array("JAN", "FEB", "MAR",
"APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
var d = new Date();
d.setDate(d.getDate() - 7);
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
var current = curr_date + "-" + m_names[curr_month] + "-" + curr_year;

jsFiddle example

关于javascript - 从当前日期减去 1 周 - javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19957308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com