File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes convert unix milli seconds to java date :-) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "convert unix milli seconds to java date :-)" Watch "convert unix milli seconds to java date :-)" New topic
Author

convert unix milli seconds to java date :-)

Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
Hi,

Anyone know how to convert unix milliseconds to java date/time variable?

i.e.
unix milliseconds = 1189579707
converts to = Wed, 12 Sep 2007 06:48:27 UTC

how can this be done in java?

Thanks in advance
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Check out the constructors of java.util.Date.


[Jess in Action][AskingGoodQuestions]
Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
aye ive tried out using java.util.Date constructor:

Date d = new Date(long);

but using unix milliseconds: 1189579707

it converts d to year 1970

if i try doing:

Date date = new Date(1189579707 * 1000);

it goes into year 1969

this is because (1189579707 * 1000) is not a correct long value, so a minus random value is created

so any idea how i can convert the unix milliseconds to Date? Please :-)

Cheers in advance
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
You can force the multiplication to be done as a long by making sure at least one of the numbers being multiplied is long:

new Date(1189579707 * 1000L)


"I'm not back." - Bill Harding, Twister
Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
sound thanks a million thats sorted it

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert unix milli seconds to java date :-)
 
Similar Threads
Milliseconds to date conversion
Converting Date Into Milliseconds?
Convert Hours to MilliSeconds
DATE/TIME
jstl miliseconds to Date