【发布时间】:2016-02-20 06:38:18
【问题描述】:
我使用org.yaml.snakeyaml.Yaml。
SimpleDateFormat 使用系统时区(UTC +6:30)。
我想要像 SimpleDateFormat 这样的 yaml 日期输出。
public static void main(String[] args) throws Exception {
String dateString = "2015-11-17 15:30:30";
/*
SimpleDateFormat will UTC +6:30 (Myanmar Timezone)
*/
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sdfDate = format.parse(dateString);
System.out.println("Date 1 " + format.format(sdfDate));
/*
Yaml will not use.
*/
Yaml yaml = new Yaml();
//yaml.setTimeZone(xxx) --> Is there way to set timezone?
Date yamlDate = (Date) yaml.load(dateString);
System.out.println("Date 2" + format.format(yamlDate));
}
输出
Date 1 2015-11-17 15:30:30
Date 2 2015-11-17 22:00:30
【问题讨论】:
标签: java yaml simpledateformat