• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert seconds to absolute time

 
Dominic Steng�rd
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dominic Steng�rd
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper!
That was just what I needed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic