在javascript中,如何将今天的时间戳复制四周

时间:2016-10-01 17:45:39

标签: javascript

这就是我今天的时间戳:

var timestampNow = Math.floor(Date.now() / 1000);

我想从现在开始将时间戳设置为4周。

我最初的猜测是使用Math.floor(Date.now(28) / 1000);

3 个答案:

答案 0 :(得分:2)

我相信这会奏效:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.1</version>
</dependency>

答案 1 :(得分:1)

javascript在日期方面并不是很好,因此您需要将日期解析为时间戳并修改毫秒数。但数学并不是很难。

var timestamp4weeks = Date.now() + (1000 * 60 * 60 * 24 * 7 * 4)
  • 毫秒=&gt;秒=== * 1000
  • 秒=&gt;分钟=== * 60
  • 分钟=&gt;小时=== * 60
  • 小时=&gt;天=== * 24
  • days =&gt;周=== * 7

答案 2 :(得分:1)

Moment.js让这很容易。以下是等效的:

var days  = moment().add(28, 'days');
var weeks = moment().add(4, 'weeks');