// note that I modified the format string slightly
SimpleDateFormat fmt = new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss'Z'");
// set the timezone to the original date string's timezone
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = fmt.parse("1998/12/21T13:29:31Z", new ParsePosition(0));
// then reset to the target date string's (local) timezone
fmt.setTimeZone(TimeZone.getDefault());
String localTime = fmt.format(date);
1 回答
尝试使用
TimeZone.getDefault()
而不是TimeZone.getTimeZone("GMT")
来自the docs:
编辑:您可以使用SimpleDateFormat解析日期(还有格式字符串的文档) . 在您的情况下,您想要(未经测试):
或者,使用两个单独的SimpleDateFormat实例,一个用于原始实例,另一个用于目标时间 .