首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在JavaScript购物中为date对象创建11天后的JavaScript代码

如何在JavaScript购物中为date对象创建11天后的JavaScript代码
EN

Stack Overflow用户
提问于 2019-03-01 08:34:48
回答 3查看 162关注 0票数 2

我想把日期注入到shopify description产品的html中

它会说

我们将从今天起+ 11天内发货.

如果是星期六或者星期天的话就会移到星期一,因为星期六或者星期天是休息日。

代码现在是这样的,但是如果需要的话,不知道如何把它移到第一个星期一

// get the destination within the DOM
var wrapper = document.getElementById('productEta'),

  // get today as a js Date object
  today = new Date(),

  // get the Unix of today (miliseconds) and add desired time (3 weeks)
  etaUnix = today.getTime() + (60 * 60 * 24 * 11 * 1000),

  // convert the new time to date object and then to a human readable string
  etaForHumans = new Date(etaUnix).toDateString();

// set the destination inner html to be what it already is
// plus a space and the human readable string.
wrapper.innerHTML += ' ' + etaForHumans;
<div id="productEta">Product will arrive by: </div>

但是脚本也有问题

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54936334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档