I want to display the difference between 2 time values as HH:mm:ss. For example, I got 2 Date objects and I have done this:
But the problem is, when I use SimpleDateFormat.format(new Date(elapsed)) to output as HH:mm:ss, it is converted to my local timezone. e.g. say if elaspedTime = 3hrs2min it would display 03:02:00 only if my computer's timezone is GMT +0:00. If i'm in say GMT +04:00, it would becomes 07:02:00.
How should i get the proper display from SimpleDateFormat(). I checked all it's constructors, there isn't anyone accept a timezone. The one accepting locale doesn't check the timezone of the Locale.
Hi Alec, actually, I think your code is fine in the sense that you certainly can do what you are doing, e.g. use two date objects, subtract them and use SimpleDateFormat as you are. Youre problem as I understand it is TimeZone. Use the Calendar object instead of the Date Object to initiate your dates and use the setTimeZone method on your calendar to set the timezones.
It's possible to do this, though I would be careful not to let this new Date object escape to any other part of the program, because it's being used in an unintended way which will confuse other programmers if they don't know exactly how this object was constructed. (May still confuse them, in fact.) If anyone prints the value fo this date without the proper format and time zone, they'll be extremely mislead about what it means. So be careful.
Anyway, if you do this, it's sufficient to use the setTimeZone() method inherited from DateFormat. No need to use Calendar here.
Looks like you have some good choices here for time differences in the ranges you gave as examples. Any chance they could get much larger? I'm not sure how the Date technique is going to work when you're into days and weeks and especially months.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
A feeble attempt to tell you about our stuff that makes us money