简体   繁体   English

有没有办法以毫秒为单位打印DateTime?

[英]Is there a way to print a DateTime in milliseconds?

I want the same result as this: 我想要与此相同的结果:

 dateTime.toDate().getTime() + ""

NOTE: That + "" converts it to a String . 注意: + ""将其转换为String

Does JodaTime's date formatter have a way to do this? JodaTime的日期格式化程序是否可以执行此操作? I want to do something like this: 我想做这样的事情:

dateTime.toString(x);

to get the same result. 得到相同的结果。 I tried this: 我尝试了这个:

new DateTime().toString("SSS")

But this prints the milliseconds in the second, which is not the same as the first example. 但这会在第二秒打印毫秒,这与第一个示例不同。

At first please note that dateTime.toDate().getTime() returns time in millis not in seconds. 首先请注意, dateTime.toDate().getTime()返回的时间以毫秒为单位,而不是秒。 Also there is no default date format to print date in millis. 也没有默认的日期格式以毫秒为单位打印日期。 You can of course implement your own DateTimeFormatter but it makes no sense compared to 您当然可以实现自己的DateTimeFormatter但与

String.valueOf(new DateTime().getMillis())

or 要么

String.valueOf(new DateTime().getMillis()/1000)

if you want result in seconds 如果您想在几秒钟内得到结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM