从Date()获取unix时间戳 [英] Getting unix timestamp from Date()

查看:171
本文介绍了从Date()获取unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过将 long 值放入<$ $($)$ @ code> Date() c $ c> Date()构造函数。例如:我可以把它当作新的日期(1318762128031)

I can convert a unix timestamp to a Date() object by putting the long value into the Date() constructor. For eg: I could have it as new Date(1318762128031).

但是之后,我如何从 Date()对象中获取unix时间戳? >

But after that, how can I get back the unix timestamp from the Date() object?

推荐答案

getTime() 检索1970年1月1日以来的毫秒数传递给构造函数。获取 Unix时间(相同,但在几秒钟内)不应该太难了。

getTime() retrieves the milliseconds since Jan 1, 1970 passed to the constructor. It should not be too hard to get the Unix time (same, but in seconds) from that.

这篇关于从Date()获取unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆