gpt4 book ai didi

javascript - 使用 Javascript 编写 future 的一天

转载 作者:行者123 更新时间:2023-11-29 17:27:49 25 4
gpt4 key购买 nike

我在网上找到了这段代码。我试图让它写下从今天起 9 天后的日期,但我不知道该怎么做。有谁知道要在此代码中更改什么?

var d_names = new Array("Sunday,", "Monday,", "Tuesday,",
"Wednesday,", "Thursday,", "Friday,", "Saturday,");

var m_names = new Array("January ", "February ", "March ",
"April ", "May ", "June ", "July ", "August ", "September ",
"October ", "November ", "December ");

var d = new Date();
var curr_day = d.getDay();
var curr_date = d.getDate();
var sup = "";
if (curr_date == 1 || curr_date == 21 || curr_date ==31)
{
sup = "st";
}
else if (curr_date == 2 || curr_date == 22)
{
sup = "nd";
}
else if (curr_date == 3 || curr_date == 23)
{
sup = "rd";
}
else
{
sup = "th";
}
var curr_month = d.getMonth();
var curr_year = d.getFullYear();

document.write(d_names[curr_day] + " " + m_names[curr_month] + curr_date + "<SUP>" + sup + "</SUP> " + " " + curr_year);

日期格式如下:2011 年 8 月 20 日星期六

最佳答案

紧接着:

var d = new Date();

写:

d.setDate(d.getDate()+9);

所以你有:

var d = new Date();
d.setDate(d.getDate()+9);
var curr_day = d.getDay();
var curr_date = d.getDate();

关于javascript - 使用 Javascript 编写 future 的一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7135460/

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