【发布时间】:2022-01-12 07:12:22
【问题描述】:
当我要与new Date().getTime() 做多时,我发现当时间> 11:59:59 时,它总是解析为00:xx:xx,例如; 12:00:00 --> 00:00:00, 12:23:56 --> 00:23:56;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date parse = null;
try {
parse = format.parse(str);
log.debug("time{}", parse);
} catch (ParseException e) {
e.printStackTrace();
}
当str = "2022-01-12 11:59:59" 运行良好;
当str = "2022-01-12 12:00:00" 效果不佳时,它给了我 00:00:00;
当str = "2022-01-12 12:15:00" 效果不佳时,它给了我 00:15:00;
当str = "2022-01-12 13:15:00" 运行良好时,它给了我 13:00:00;
【问题讨论】:
-
因为在午夜,新的一天开始了
-
您将日期解析为 1-12 小时字符串并将其打印为 0-23 小时字符串。你期待什么。 12 AM == 00 24 小时制。
-
SimpleDateFormat- 你为什么还在使用?
标签: java date parsing simpledateformat