Java 中将字符串解析为日历的问题
Issues parsing a String into a Calendar in Java
当我尝试以下代码时,
public static void main(String[] args) throws ParseException{
try {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
calendar.setTime(sdf.parse("Sun Feb 22 18:02:51 FET 2015"));
} catch (Exception e) {
e.printStackTrace();
}
}
我系统地得到
java.text.ParseException: Unparseable date: "Sun Feb 22 18:02:51 FET 2015"
at java.text.DateFormat.parse(DateFormat.java:357)
at foo.Sample.main(LogEntry.java:131)
我知道我的问题是 FET 时区。那是一个有效的时区。我尝试了不同的方法,包括使用 Locale.English
但无济于事。
我的问题似乎是由时区引起的 here。
编辑
以下也不行
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
这是another post我找到但没有帮助我。
Java好像不支持场效应管
使用MSK。
当我尝试以下代码时,
public static void main(String[] args) throws ParseException{
try {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
calendar.setTime(sdf.parse("Sun Feb 22 18:02:51 FET 2015"));
} catch (Exception e) {
e.printStackTrace();
}
}
我系统地得到
java.text.ParseException: Unparseable date: "Sun Feb 22 18:02:51 FET 2015"
at java.text.DateFormat.parse(DateFormat.java:357)
at foo.Sample.main(LogEntry.java:131)
我知道我的问题是 FET 时区。那是一个有效的时区。我尝试了不同的方法,包括使用 Locale.English
但无济于事。
我的问题似乎是由时区引起的 here。
编辑
以下也不行
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
这是another post我找到但没有帮助我。
Java好像不支持场效应管
使用MSK。