java为什么是DateFormat。格式(日期),给出与日期不同的时间。toString()?
我在代码中观察到这种奇怪的行为-
Date executionDate = execDao.getExecutionDate(id);
System.out.println(executionDate);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(dateFormat.format(executionDate));
这就给出了输出
2014-03-05 22:10:46.0
2014-03-05 10:10:46
为什么输出的小时数不同
# 1 楼答案
第一种方法默认为24次。第二个是12小时,因为这是你指定的时间。将第二个函数调用更改为
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
获取24小时格式http://developer.android.com/reference/java/text/SimpleDateFormat.html