Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Time.toString() format  RSS feed

 
Paul Hennessey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I hope this isn't just because I'm too tired to think straight any more but here goes:

My app logs events, and timestamps them with a long integer. In order to work out the interval between two events I'm trying to subtract one from the other and output the difference, like this:



By my calculations, that comes to around 11 seconds. But instead of getting 00:00:11, I get 01:00:11.

Can anyone explain why this is happening?

Thanks,

Paul
 
Tom Henner
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul- I don't have access to Time to test- but could it be the locale is the problem? If you pass in the start and end values they do seem 11 seconds apart. Maybe try passing those into Time and printing.
 
Paul Hennessey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion Tom. I think I know whats happening now.

The Time class is a 24 hour clock that starts at 01:00:00. So if you create a Time object and initialise it with 0, you get 01:00:00. If you create a Time object and initialise it with 3600000 (one hour in milliseconds), you get 02:00:00, etc.

This means that this class is no use to me, as it wraps round after 24 hours. Guess I'll just have to do some work and write my own formatting code <sigh>.

Paul
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!