11-06-2012 11:04 AM
You need to think hard about what times are, and which times are invariant and which times should change when you change time zone.
If these are invariant times, then the easiest way to process them is to create a local time Calendar object, then substring the date and set the Month, year, day yourself (and clear the time). Then when you display this, you will see local time.
Alternatively, create GMT Calendar, set the times, then display these using a DateField that also uses a GMT Time Zone.
And since these came from a Server, you may need to be aware of the time that it thinks it is.
11-06-2012 11:09 AM
Thanks Peter. I will just be comparing dates and just need to ensure the correct timezone (ofset) is used when httpdateparse. I can ge the -4 (or -5 etc. depending on timezone on device) and just need to fiormat is as hr (eg "-04:00") so I can append to my date. Is this something that can be done efficiently? I'm in the process of researching dates/times/zones now. Trying to get this all sorted out.
11-06-2012 11:30 AM - edited 11-06-2012 11:45 AM
Looks like I might have it. May be overkill, not sure. This seems to work to return the correct date.
//break down string date and pass in params
TimeZone clientZone = TimeZone.getDefault();
Calendar cal = Calendar.getInstance(clientZone);
cal.set(Calendar.MONTH, 11 - 1);
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date(cal.getTime().getTime()));
Doesnt seem like clientZone is required. Is this the correct approach to setting a calendar object from a string?
11-06-2012 01:11 PM
Code is exactly what I would do, except I would probably use
But remember if the user changes time zone between the cal.set... and the String date, then the time will be wrong.