gpt4 book ai didi

javascript - 调整日期差异

转载 作者:行者123 更新时间:2023-12-02 17:34:25 25 4
gpt4 key购买 nike

以下脚本获取所选日期加上之后59天,我需要帮助将其修改为前后30天(所选日期前30天+所选日期+所选日期后30天)。

<script lang="javascript">
function setOptions(selected_holiday)
{
sh = new Date();
aDay = 24*60*60*1000;
sh_year = selected_holiday.substr(0, 4) ;
sh_month = selected_holiday.substr(4, 2) - 0;
sh_day = selected_holiday.substr(6, 2) ;
sh.setFullYear(sh_year,sh_month-1,sh_day);
sh.setTime(sh.getTime()+aDay);

sh_max = new Date(sh.getTime()+(59*aDay)+aDay);
var defoff_date = document.deferform.defoff_date;
defoff_date.options.length = 0;

for (i=sh.getTime();i<sh_max;i+=aDay) {
date = new Date(i);
year = date.getYear();
slash = "/";
if (year < 1900) year += 1900;
strDay = "0"+ date.getDate();
strDay =strDay.substr(strDay.length-2,2);
strMonth = "0"+ (date.getMonth()+1);
strMonth = strMonth.substr(strMonth.length-2,2);
strDate = "" + strMonth + slash + strDay + slash + year;
defoff_date.options[defoff_date.options.length] = new Option(strDate);
}
</script>

最佳答案

这是执行计算的行:

sh_max = new Date(sh.getTime()+(59*aDay)+aDay);

此后,shsh_max 分别为“现在”和“六十天后”。

如果你把它改成

sh_min = new Date(sh.getTime()-30*aDay);
sh_max = new Date(sh.getTime()+30*aDay+aDay);

那么 sh_minsh_max 将是“三十天前”和“三十一天后”。您还可以更改循环以反射(reflect)新的变量名称:

for (i=sh_min.getTime();i<sh_max;i+=aDay) {

关于javascript - 调整日期差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22753520/

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