Javascript Unixtime
Just a note of how to get Unixtime in Javascipt.
var date_obj = new Date;
var unixtime_ms = date_obj.getTime();
var unixtime = parseInt(unixtime_ms / 1000);
Also a Javascript Unixtime conversion utility.
Just a note of how to get Unixtime in Javascipt.
var date_obj = new Date;
var unixtime_ms = date_obj.getTime();
var unixtime = parseInt(unixtime_ms / 1000);
Also a Javascript Unixtime conversion utility.
Thanks for this snippet. You saved me a lot of time.
yeah thx mate
Brilliant, thanks. Just what I was looking for.
Great little script. Thanks for sharing
Great example ! keep it simple and everyone understand
thx, exactly what I need.
Use multiplication over division, it's much faster. Also, Math.Floor is faster than parseInt var unixtime = Math.Floor(unixtime_ms.valueOf() * 0.001);
Use the optimizations Andrew gave. Plus, faster still than Math.floor is:
var unixtime = (new Date().getTime() * 0.001)|0;
Because it removes the extra namespace lookup and function call (see Ecmascript spec 11.10 - the behavior is explicitly specified).
Also, valueOf (as per Andrew's comment) is slightly faster than getTime:
var unixtime = (new Date().valueOf() * 0.001)|0;
Thanks man! Saved me TONS(!!!) of time.
parseInt(+new Date() / 1000);