开发者

Converting date in string to specified locale on Android

开发者 https://www.devze.com 2023-04-01 03:21 出处:网络
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:

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.

开发者_C百科

Any ideas?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消