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

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

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

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

它会说

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

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

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

代码语言:javascript
运行
AI代码解释
复制
// 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;
代码语言:javascript
运行
AI代码解释
复制
<div id="productEta">Product will arrive by: </div>

但是脚本也有问题

EN

回答 3

Stack Overflow用户

发布于 2019-03-01 00:52:09

代码语言:javascript
运行
AI代码解释
复制
// 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);
  var day = etaForHumans.getDay()
  if(day==0)
      etaForHumans.setDate(etaForHumans.getDate() + 1);
  if(day==6)
      etaForHumans.setDate(etaForHumans.getDate() + 2);

// set the destination inner html to be what it already is
// plus a space and the human readable string.
wrapper.innerHTML += ' ' + etaForHumans+ ' ' + day;
代码语言:javascript
运行
AI代码解释
复制
<div id="productEta">Product will arrive by: </div>

票数 0
EN

Stack Overflow用户

发布于 2019-03-01 00:53:03

代码语言:javascript
运行
AI代码解释
复制
var wrapper = document.getElementById('productEta');
var today = new Date(Date.parse('2019-03-05'));
var etaDate = new Date(today.getTime() + (60 * 60 * 24 * 11 * 1000))
while(etaDate.getDay() == 0 || etaDate.getDay() == 6){
	//Add one day until it is not saturday or sunday
	etaDate.setTime(etaDate.getTime() + (60 * 60 * 24 * 1000));
}

var etaForHumans = etaDate.toDateString();
// set the destination inner html to be what it already is
// plus a space and the human readable string.
wrapper.innerHTML += ' ' + etaForHumans;
代码语言:javascript
运行
AI代码解释
复制
<div id="productEta">Product will arrive by: </div>

票数 0
EN

Stack Overflow用户

发布于 2019-03-01 05:03:13

momentJS。看看这个。允许你以一种理智的方式处理日期。有用于请求nextBusinessDay()和更多内容的插件。

不要摆弄日期和普通的Javascript,除非你是一个高手Javascript程序员。它很糟糕,momentJS的存在是有充分理由的。更少的差劲。

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

https://stackoverflow.com/questions/54936334

复制
相关文章
使用 htaccess 将旧域名 301 重定向到新域名
如果更换了域名,那么为了把原来的域名的权重都转移到新域名上面,最好的方法是 301 重定向,我们可以使用 htaccess 将旧域名重定向到新域名,具体方法如下:
Denis
2023/04/15
4.1K0
将网站http跳转至https,并将www域名重定向至不带www
实现了将http://liaobu.de, http://www.liaobu.de, https://www.liaobu.de 都跳转至https://liaobu.de 的效果
wo.
2021/06/15
3.5K0
如何将域名http转换成https?
分享一篇将自己的域名由http转换成https的文章,由http转https首先要有个备案的域名和一个可用的服务器,然后在自己的服务器上安装ssl证书所对应的服务,先用tomcat的服务做演示。
技术从心
2019/08/06
12.3K1
如何将域名http转换成https?
如何将HTTP重定向到Apache上的HTTPS
HTTP ( 超文本传输​​协议 )是万维网 ( WWW )上数据通信的基本协议; 通常在Web浏览器和存储Web文件的服务器之间。 而HTTPS是HTTP的安全版本,其中“ S ”端代表“ Secure ”。
子润先生
2021/06/15
4.6K0
Chrome 将 http 域名自动跳转 https 的解决方案
使用 Chrome 内核浏览器,包括 Google Chrome,edge,360浏览器等。
白墨石
2022/09/27
5.7K0
Chrome 将 http 域名自动跳转 https 的解决方案
Nginx 重定向所有子域名到www
vim .htaccess  或  vim  /var/www/html/.htaccess
阳光岛主
2019/02/18
6.3K0
Nginx 重定向所有子域名到www
https域名配置
大部分免费证书(指阿里/腾讯申请的),下载本地后,解压都会有以下四个文件夹。宝塔面板只需要用到nginx或apache的,其他无需理会。 请根据你的服务器web环境查看下列文档:
西里国际站
2023/04/19
3.6K0
Hexo,自定义域名http升级https
  数数手指头,我这基于 Hexo + GitHub Page 搭起来的个人博客也有两个月时间了,之前就想过把 http 升级为 https,无奈因为各种原因也就被搁置下来了。今天,我这博客终于升级到 https 了。好东西第一时间是写出来分享,何况这操作真的很简单。
happyJared
2018/09/20
1.9K0
Hexo,自定义域名http升级https
一级域名301重定向到www二级域名
(1)test.com(2)www.test.com(3)test.com/default.html(4)www.test.com/default.html
全栈程序员站长
2022/08/31
3.5K0
istio: http 流量 301重定向到 https
下面截取本站 Gateway 配置中的一部分,只需添加最后两行即可实现流量重定向。
SRE扫地僧
2021/10/07
2.7K0
istio: http 流量 301重定向到 https
12.9 Nginx域名重定向
Nginx域名重定向目录概要 更改test.com.conf server { listen 80; server_name test.com test1.com test2.com; index index.html index.htm index.php; root /data/wwwroot/test.com; if ($host != 'test.com' ) { rewrite ^/(.*)$ http://test.com/$1 pe
运维小白
2018/02/06
8.4K0
nginx设置http 301重定向到https
  今天有位客户问ytkah在nginx服务器如何设置http 301重定向到https,其实不难。他的服务器安装宝塔面板了,更好操作了。进入站点设置的配置文件,如下图所示,在第11行左右加入跳转代码  
ytkah
2020/03/25
12.4K0
域名301重定向
 301重定向又被称为301转向或301跳转,指的是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态马的一种,表示本网页永久性转移到另一个地址。301重定向是网页更改地址后对搜索引擎友好的最好方法,只要不是暂时转移网址,都建议使用301来做转址。
用户2590762
2021/08/11
4.7K0
将hexo自定义域名升级https
最近在折腾博客,发现github上很多人说个人博客支持https很重要,原本的github.io域名本来支持https协议,但是在自定义域名之后,协议变成了http。这使得网站变得不够安全,容易被劫持。
benym
2022/07/14
1.4K0
将hexo自定义域名升级https
Exchange 禁止特定用户发往特定域名邮件
创建集线器传输规则 勾选来自用户、当收件人包含特定词语,输入@qq.com 操作选择删除邮件而不通知任何人 测试下发送情况,往QQ发送了个测试邮件,下面看看传递报告,可以看到发往QQ的邮件邮件被规则阻
李珣
2019/03/14
3.1K0
域名对应重定向跳转
有的时候会更换域名,但是旗下有很多分站,二级域名;如: ilkhome.cn 要重定向到 dopan.net qrpay.uomg.com 到 qrpay.aeink.com
似水的流年
2019/12/05
5.3K0
域名重定向是什么意思啊?域名重定向应该怎么处理?
网页是网络的基础,很多操作都需要通过网站来进行,但是有时候打开某个网页,却会显示域名重定向,一些没有经验的人并不知道域名重定向是什么意思。下面来为大家介绍一下域名重定向是什么意思,以及域名重定向应该怎么处理?
用户8739990
2021/08/13
6.5K0
DTcms4/5中使用HttpModule将http访问301重定向到https
前面虽然讲过SSL在IIS开启的几种方式,比较常见的Microsoft URL Rewrite Module修改Web.Config如下:
崔文远TroyCui
2019/02/26
1.6K0
DTcms4/5中使用HttpModule将http访问301重定向到https
设置HTTP重定向为HTTPS
更多关于重定向内容:https://jingyan.baidu.com/article/09ea3ede6bd7c6c0aede3931.html 敲黑板,如果.htaccess文件中原本就有伪静态代码,要把上面的代码放在URL-rewrite代码之前。
林清猫耳
2018/12/19
2.1K0
Nginx用户认证与域名重定向
如果再次添加用户的话就不需要加上-c选项了,加上-c选项会覆盖原来的htpasswd 文件。
端碗吹水
2020/09/23
3.3K0
Nginx用户认证与域名重定向

相似问题

使用https将域名重定向到其他域名

10

.htaccess http到https特定域名多个域重定向

10

将NGINX HTTPS域名重定向到新的HTTPS域名

111

nginx将http重定向至https域名

118

对于特定域名,如何在.htaccess中将HTTPS重定向到HTTP?

10
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文