javascript - 添加日期更改脚本
问题描述
我有这段代码显示第二天的日期。是否可以更改日期的行为,使其在 17:00 更改?例如,现在代码显示日期 16.6.2020(这是正确的),17:00 之后应该显示 17.6.2020
document.querySelector("a[href='data']").setAttribute("id", "day");
document.querySelector("a[href='data2']").setAttribute("id", "day2");
var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.getElementById("day").innerHTML = day + "." + month + "." + year;
document.getElementById("day2").innerHTML = day + "." + month + "." + year;
<a class="tn-atom" href="data" id=""></a>
<a class="tn-atom" href="data2" id=""></a>
解决方案
如果您不想弄乱时区,请将日期添加 7 小时,以便在 17:00 显示下一天的日期
var currentDate = new Date(new Date().getTime() + 31 * 60 * 60 * 1000);
console.log(currentDate)
// testing DST
const aroundDST = new Date(2020,2,29,0,0,0,0); // 29th of March 2020 - DST-SST in most of Europe
const afterDST = new Date(aroundDST.getTime() + 31 * 60 * 60 * 1000);
console.log(afterDST)
推荐阅读
- boxplot - sns.boxplot 中的 Wish 参数在更改时不会反映在图形上
- java - 我可以使用 MongoRepository 从另一个集合中检索数据吗?
- php - PHP 中的关联
- php - 在 laravel 中创建外键时出现错误
- node.js - 错误:调用 passport.serializeUser 时无法读取 null 的属性“用户”
- arrays - 如何使用术语查询在此数组中进行搜索?
- c# - 使用 IEnumerable 作为只读列表会更好吗?
- sqlite - (sqlite) 如何跨四个表共享同一个主键
- ffmpeg - 使用 ffmpeg 将视频转换为帧时出错
- python - 如何在 QTableView 单元格中显示具有原始大小比例的图像?