-1
我有时间格式转换奇怪的问题。simpledateformat更改时区
我有串,时间= “11:00”
我上面的字符串转换日期和我做了以下内容:
Calendar cal= Calendar.getInstance();
cal.setTime(Convert.fromShortTime(timeIn)); // this method is below
public static SimpleDateFormat SHORT_TIME = new SimpleDateFormat("HH:mm");
public static Date fromShortTime(String shortTime)
{
try {
return shortTime == null ? null : SHORT_TIME.parse(shortTime);
} catch (ParseException e) {
return null;
}
}
所以cal.setTime(Convert.fromShortTime( timeIn));将数值更改为: Thu Jan 01 10:00:00 PST 1970这比字符串少了1小时。
我的笔记本电脑时间是山区时间和设备时间是太平洋时间。 如果我将笔记本电脑的时间更改为太平洋,那么它的工作正常。
我想知道为什么Android Studio的笔记本电脑时间会影响SimpledateFormat?