my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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: 14074
    
  16

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.
 
 
subject: Convert seconds to absolute time
 
Similar Threads
How can I read property files under tomcat
Scheduled Tasks in Java. Help!!!
Retrieving System Time in Micro Seconds
[Easy]find the angles between the hands
time pattern for milli second