• Post Reply Bookmark Topic Watch Topic
  • New Topic

Time creation confusion  RSS feed

 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have an int value representing a # of minutes..

int minutes = 120;

now if I create a new Time() based on those minutes.. I'm getting an extra hour for some reason..

E.g.

Time t = new Time(minutes * 60 * 1000);

t.toString() will be 03:00 rather than 02:00 - 120 minutes is two hours so I dont see why the extra hour ?

Any thoughts ?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is this Time class? Did you write it yourself? If so, can you show us part of its code, especially the private fields, constructor and toString() methods?
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you go through the Time class, you find it is only intended for use with JDBC/databases. You also find out that the time you pass is calculated after midnight 1st Jan 1970. What you don't know (being doubtless too young to remember) is that by midnight 1st Jan 1970 we had all sung "Auld Lang Syne" and swilled our drinks an hour previously, because we had to suffer Summer Time all winter that year, and the clocks all showed 1.00am. So 2 hours after midnight when in Summer Time is 3.00am.
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If you go through the Time class, you find it is only intended for use with JDBC/databases. You also find out that the time you pass is calculated after midnight 1st Jan 1970. What you don't know (being doubtless too young to remember) is that by midnight 1st Jan 1970 we had all sung "Auld Lang Syne" and swilled our drinks an hour previously, because we had to suffer Summer Time all winter that year, and the clocks all showed 1.00am. So 2 hours after midnight when in Summer Time is 3.00am.


Ahhh so its probably a timezone issue !
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I was trying to do was use String.format() to output the number of minutes (120) as HHMM format, 0200.

but instead I am getting 0300...

So I'm not quite sure what to do now.. I guess I need to determine what the timezone is thats being used and whether it definately is that causing this issue..

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't the Calendar class be any help. Once you do have the date or time, I think the SimpleDateFormat class will make things simpler for displaying dates and times.
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I tried using the calendar, and setting the calendar timezone to GMT, and outputting the toString() to debug it, and the toString() showed the time was now correct 02:00...

However as soon as I passed in the calendar.getTime() into my String.format() call, then the output was once again 03:00 +0100...

So for now I'm just using SimpleDateFormatter and setting the timezone on that.. It works.

Thanks for assistance.

 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

But you might have been better off doing what Rob thought you had done, writing your own Time class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!