Joda DateTime到Unix DateTime [英] Joda DateTime to Unix DateTime
问题描述
这很奇怪,但我没有找到任何关于将Joda(时间) DateTime
转换为Unix DateTime(或时间戳,无论哪个名称正确)的结果。我该怎么做?
It's odd enough, but I didn't find any result about converting Joda(Time) DateTime
to Unix DateTime (or timestamp, whichever is the correct name). How can I do this?
推荐答案
任何继承自 BaseDateTime
的对象(包括 DateTime
)有方法
Any object that inherits from BaseDateTime
(including DateTime
) has the method
public long getMillis()
根据 API 它:
从1970-01-01T00:00:00Z的Java纪元获取日期时刻的毫秒数。
Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.
所以a得到秒的工作示例就是:
So a working example to get the seconds would simply be:
new DateTime().getMillis() / 1000
为了完整性,根据维基百科的Unix时间戳:
Unix时间,或POSIX时间,是一个用于描述时间瞬间的系统,def自1970年1月1日星期四00:00:00世界协调时间(UTC)以来经过的秒数,不计算闰秒
Unix time, or POSIX time, is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds
这篇关于Joda DateTime到Unix DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!