1
YAML文件:为什么YAML解析的时间戳不正确?
!!test.User
timestamp: 2012-11-22T01:02:03.567Z
Java类:
package test;
public class User {
public Date timestamp;
}
与snakeyaml解析它:
String str = "2012-11-22T01:02:03.567Z";
// parse it manually
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(str);
System.out.println("manually: " + date);
// parse it by snakeyaml
Yaml yaml = new Yaml();
yaml.setBeanAccess(BeanAccess.FIELD);
InputStream input = new FileInputStream("C:\\test.yaml");
User myUser = yaml.loadAs(input, User.class);
System.out.println("by Yaml: " + user.timestamp);
它打印:
manually: Thu Nov 22 01:02:03 CST 2012
by Yaml: Thu Nov 22 09:02:03 CST 2012
你可以看到他们是d ifferent。为什么?
除非是中国标准时间。 –
@MichałPolitowski好点,我讨厌它时,不同的时区有相同的缩写:-( – Henry
这就是为什么一个人应该避免3个字母的时区代码,而是使用[适当的时区名称](https:// en。例如:“美国/芝加哥”或“亚洲/台北”而不是“CST”。 –