开发者

javascript unixtime one minute in front

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 开发者_StackOverflowwould be helpful.

Thanks


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;


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


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);


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜