File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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: 14269
    
  21

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 8 API documentation
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