11-10-2011 09:30 AM
11-10-2011 09:54 AM
Here is an example of the problem I am facing...
This works fine and produces the correct date/time as Nov 10, 2011 1:47 PM...
DateField dfSomeDateTime = new DateField("", someDateTime.longValue(), DateField.DATE_TIME);
Dialog.inform("df: " + dfSomeDateTime.toString());
This produces the date in the proper format but 7 hours behind (2011-11-10 06:47:58)...
StringBuffer sb = new StringBuffer(10);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss aaa");
Date tempDate = new Date(someDateTime.longValue());
Calendar gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone(DateTime
sb = sdf.format(gmtCalendar, sb, null);
Dialog.inform("sb: " + sb.toString());
Any thoughts as to why?
11-10-2011 09:58 AM
If that's the case then the long value you have stored is, when baselined with UTC, 7 hours out of what it should be. So add 7 hours to it.
It's important that you make sure, when storing the long values, that they are UTC base lined, which is normally the case if you get them using the Date or Calendar classes. You have to be consequent with their use. Don't try to be clever and manipulate the long yourself.
11-10-2011 10:16 AM
The only thing I do with this long value before storing it is sometimes add a couple hours like so...
long someDateTime = System.currentTimeMillis() + (5 * DateTimeUtilities.ONEHOUR); //now + 5 hrs
dateTable.put("SomeDateTime", new Long(someDateTime));
That about code should be fine. Can;t see what would be wrong here.
11-10-2011 10:56 AM
I think you really need to think about what you want. It is tricky. Some things are adjusted according to locale, something's are not. Some times you want to be adjusted, some you don't. Some you want to at fixed time in the day regardless of where you are, some you don't.
Take another example, I am booking an appointment. The meeting is with a colleague in San Francisco. I am in the UK. The meeting takes place at 9:00. I put that time in my Calendar. My colleague also puts that time in his Calendar, but he lives in SF. Now convert these times to UTC time. According to UTC time (remember I am in the UK), we will miss each other by 8 hours. But when I fly to SF, my BlackBerry adjusts the time it displays to match the local time zone.
But also there is a big game I want to watch, in NY at 5:30 in the evening. I can't put this in my Calendar can I? I don't want this time to be 'local time'.
So what do you want. Tell us what you are trying to achieve and perhaps we can tell you what you need to do.
Responding to the post that begins:
"Here is an example of the problem I am facing..."
Remember also that DateField is adjusted to local time. You can give it a Time Zone, and you give it a SimpleDateFormat. If you give it GMT (which is close enough to UTC to not matter) and tell it to use this format:
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss aaa");
it will display the same as the code.
11-10-2011 11:02 AM
Thanks Peter. I see what you are saying and understand. All I need my app to do is get the current date time, add a couple hours to it then display it as yyyy-MM-dd hh:mm:ss aaa. No concern for the time zone or dst, etc. Users wont be travelling or comparing to anything other than the datetime on their own device. Any thoughts as to why my "Here is an example of the problem I am facing..." code isn;t working as expected? Thanks a lot.