Android Time.format("%a")给出错误的星期几

Fra*_*per 2 android strftime

我正在尝试检索给定时间戳的本地化日期.我的代码是这样的

String timestamp = "2011-08-01T15:55:03.000+02:00";
Time time = new Time();
time.parse3339(timestamp);
// In strftime format "%a" should be the abbreviated weekday name
// according to the current locale.
String result = time.format("%a")
Run Code Online (Sandbox Code Playgroud)

由于2011年8月1日是星期一,结果字符串应该是"星期一"(假设是英语语言环境),而是"Sun"!

Fra*_*per 5

必须调用time.normalize(),否则weekDay,yearDay,isDst和gmtoff的值都将为0.

正确的代码是:

time.parse3339(timestamp);
time.normalize(false);
String localizedDayOfWeek = time.format("%a")
Run Code Online (Sandbox Code Playgroud)

感谢Femi,他指出在某些情况下,时间可以通过time.parse3339()转换为UTC,从而使我走上正轨.