12-20-2012 02:08 AM - edited 12-20-2012 02:09 AM
SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss"); final DateField timeField = new DateField("", 0, timeFormat);
Heres how I am trying to format, then I'm filling timeField with my
I am triyng to show the time between my events, it all formats fine (minutes and seconds) but the hour field of the formatted string always shows the current our of the day and not hour between my events!?!
It should always start at 0 and then increase every hour. I dont want it to show the hour of the day, but the hour of my own timer
I find it weird that all the other fields work fine, not showing the minute or second in the day but the hour field won't give.
Solved! Go to Solution.
12-20-2012 02:40 AM
12-20-2012 03:51 AM
12-20-2012 05:03 AM
I use DateField for this purpose. Hours and minutes display correctly.
What you have not considered is that the DateField is TimeZone specific and by default, uses the local TimeZone. So, say you give it a time of 1 hour, then this actually means 1 hour past midnight on the Epoch. Now the Epoch is UTC, so this time will then get converted to what every 01:00 on the 1 Jan 1970 would be in your TimeZone. That is the problem you are having.
To overcome this problem, is simple, Just set the TimeZone for the DateField to be GMT. And this should resolve your problem.
If you are using this as an input Field, then you really have to be aware that it actually displaying a date - just not showing the Date part. So when you do a getTime() from the Field you have to extract just the hour and minute and ignore the date part. For example, say you display 18:00 because the user has been doing something for 18 hours. The user changes this to 1:00 and being sensible, rolls the control up to 19, 20, 21, etc to 1. Then the DateField will give you back the next day (i.e. 25 hours) not 1 hour. Same happens if the user rolls the time back.
So the trick is set the TimeZone on the DateField to GMT, and make sure you factor out any Date component if you are using this for input.
Hope this is clear.