[英]Change day after hour js html
我有一个代码:
var dayNames = new Array("wednesday", "wednesday", "thursday", "friday", "wednesday", "thursday", "friday"); var now = new Date(); document.write("Buy nowe, you geti it on " + dayNames[now.getDay()]);
<a id="orderBy"></a>
我想在下午 2 点之后更改一天。 有人可以帮我吗?
像这样 - 我假设周五之后的任何一天 14:00 和周三之前的 14:00 意味着周三交货
const dayNames = ["wednesday", "wednesday", "thursday", "friday", "wednesday", "thursday", "friday"]; let now = new Date(); if (now.getHours() >= 14) now.setDate(now.getDate()+1) document.write("Buy nowe, you geti it on " + dayNames[now.getDay()]);
<a id="orderBy"></a>
您可以将时间设置为从现在起 14 小时。 因此,如果是下午 2 点或之后,则将被视为次日凌晨 12:00 及之后。
let shippingTime = new Date();
shippingTime.setHours(shippingTime.getHours() + 14);
document.write("Buy now, you get it on " + dayNames[shippingTime.getDay()]);
<a id="orderBy"></a>
尝试这个
var now = new Date();
var day = now.getDay();
if (now.getHours() >= 14){
day += 1;
}
document.write("Buy nowe, you geti it on " + dayNames[day]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.