我已经写了下面这个方法:
private static String getDate(final long addToCurrentMillis, final String pattern) {
final long timeMilliseconds = System.currentTimeMillis() + addToCurrentMillis;
final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
final Date resultdate = new Date(timeMilliseconds);
final TimeZone timeZone = TimeZone.getDefault();
sdf.setTimeZone(timeZone);
return sdf.format(resultdate);
}
我使用了"yyyy-MM-dd zzz"
格式,结果是:
2015-10-24 EEST
我在进行单元测试时使用了这种方法。问题在于,我试图将此字符串转换回要测试的代码中的TimeZone
,但TimeZone
不知道EEST时区。有什么想法吗?
String
转换回Timezone
的?你遇到了什么错误? - Gaël J