This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Convert seconds to absolute time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert seconds to absolute time" Watch "Convert seconds to absolute time" New topic
Author

Convert seconds to absolute time

Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
Hi fellow ranchers!

I have a class that returns seconds as an int (172800), but I need this data as an absolute time (yyMMddHHmmss).

Which is the best way using the java class libraries?
Thanks in advance.

Kind regards


Dominic Steng�rd<br />Sun Certified Java 2 Programmer
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

I guess the seconds are the number of seconds since a predefined start time (for example January 1, 1970, 00:00 GMT)?

Create a java.util.Date object, set the time on the object using your number of seconds (you'll have to multiply it with 1000 to get milliseconds), and use java.text.SimpleDateFormat to format it to a string in the desired format. See the API documentation.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
Thanks Jesper!
That was just what I needed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert seconds to absolute time
 
Similar Threads
Scheduled Tasks in Java. Help!!!
Retrieving System Time in Micro Seconds
[Easy]find the angles between the hands
time pattern for milli second
How can I read property files under tomcat