javascript unixtime 前面一分钟

发布于 2024-08-26 03:48:36 字数 130 浏览 3 评论 0原文

您好,我正在将 unixtimestamp 传递给 javascript IF 语句,任何人都可以告诉我如何使用 javascript 生成未来一分钟的 unixtimestamp 。

任何帮助都会有所帮助。

谢谢

Hi I'm passing a unixtimestamp to a javascript IF statement, can anyone tell me how to generate a unixtimestamp one minute in the future with javascript.

Anyhelp would be helpful.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一生独一 2024-09-02 03:48:36

JavaScript Date 对象 有一个 getTime() 方法返回自 1970 年以来的毫秒数。要使其看起来像 UNIX 时间戳,您需要除以 1000 并四舍五入(使用 Math.floor())。添加 60 即可提前一分钟。

var d = new Date();
var unixtimeAdd60 = Math.floor(d.getTime()/1000)+60;

The JavaScript Date object has a getTime() method that returns milliseconds since 1970. To make this look like a UNIX timestamp, you need to divide by 1000 and round (with Math.floor()). Adding 60 get's your one minute ahead.

var d = new Date();
var unixtimeAdd60 = Math.floor(d.getTime()/1000)+60;
無心 2024-09-02 03:48:36

UNIX 时间只是自 1970-01-01Z 以来的秒数。因此,只需添加 60,您就会在一分钟后获得时间戳。

UNIX time is just the number of seconds since 1970-01-01Z. So just add 60 you'll get a timestamp one minute later.

ゞ花落谁相伴 2024-09-02 03:48:36

JavaScript Date 对象的 getTime返回自 1970 年 1 月 1 日午夜以来的毫秒数。

试试这个。

var oneMinLater = new Date().getTime() + 60 * 1000;
var d = new Date();
d.setTime(oneMinLater);

JavaScript Date object's getTime returns the number of milliseconds since midnight Jan 1, 1970.

Try this.

var oneMinLater = new Date().getTime() + 60 * 1000;
var d = new Date();
d.setTime(oneMinLater);
如梦初醒的夏天 2024-09-02 03:48:36

另一种以简单的方式获取 unix 时间戳(这是从 1970 年 1 月 1 日开始以秒为单位的时间)的方法是:

var myDate = new Date();
    console.log(+myDate + 60); // you just sum the seconds that you want
    // +myDateObject give you the unix from that date

Another way to get the unix timestamp (this is time in seconds from 1/1/1970) in a simple way its:

var myDate = new Date();
    console.log(+myDate + 60); // you just sum the seconds that you want
    // +myDateObject give you the unix from that date
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文