开发者

how to convert seconds_since_the_beginning_of_this_epoch to date format in java..?

开发者 https://www.devze.com 2023-02-26 14:13 出处:网络
How to convert seconds_since_the_beg开发者_如何学Cinning_of_this_epoch (ssboetod) to date format in java..?

How to convert seconds_since_the_beg开发者_如何学Cinning_of_this_epoch (ssboetod) to date format in java..?

for example:

I will have number in ssboetod format:

987777000

And I want it to be in normal date format:

Fri Apr 20 20:00:00 2001.


If by "this epoch" you mean the normal unix epoch, you can just multiply by 1000:

Date dt = new Date(987777000000L);

Java dates are measured in milliseconds since the Unix epoch.

As ever though, I would strongly recommend that you look at using Joda Time instead of the built-in Java date/time APIs... Joda Time is much nicer. (You'd still use the same value to construct an Instant though.)


Look up the javadoc for java.util.Date(long)


java.text.DateFormat


    long s = 987777000L * 1000L;
    Date d = new Date(s);
    System.out.println(d);
0

精彩评论

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