运行这个程序:
import java.text.*;
import java.util.*;
public class xx {
public static void main(String[] args) throws Exception {
final SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
format.setLenient(false);
format.parse("Tue, 16 Jan 2010 04:41:09 -0000");
}
}
Run Code Online (Sandbox Code Playgroud)
给出这个结果(java version "1.7.0_17"):
Exception in thread "main" java.text.ParseException: Unparseable date: "Tue, 16 Jan 2010 04:41:09 -0000"
at java.text.DateFormat.parse(DateFormat.java:357)
at xx.main(xx.java:7)
Run Code Online (Sandbox Code Playgroud)
看来,当设置为非宽松模式时,Tue,前缀是无法解析的.
问题是,为什么EEE,不能匹配Tue,日期字符串的前缀?
那是因为1月16日不是星期二,而是星期六.
public static void main(String args[]) throws ParseException {
final SimpleDateFormat format = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
format.setLenient(false);
format.parse("Sat, 16 Jan 2010 04:41:09 -0000");
}
Run Code Online (Sandbox Code Playgroud)
工作得很好.
| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |