Search code examples
androiddatelocale

Converting date in string to specified locale on Android


I have this date in string:

"2011-08-28 08:30:00 +0000"

I want this to convert to a java.util.Date in hungarian Locale, so I try to use this formatter:

DateFormat currentDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", new Locale("hu"));

I am expecting that with currentDateFormat.parse I get "2011-08-28 10:30:00" as date (Hungary is GMT+2) but it is still "2011-08-28 08:30:00". I've tried to use setTimeZone(TimeZone.getDefault()) but didn't help.

Any ideas?


Solution

  • Android only uses UTC, no more GMT.

    The problem is the date you have there is not clearly UTC and Android doesn't know what to do with it so it's default behavior is to just assume your date is in the current time zone.