gpt4 book ai didi

Java日期格式奇怪

转载 作者:行者123 更新时间:2023-12-01 06:34:58 24 4
gpt4 key购买 nike

我有一个问题,我想开始一天的工作,但它似乎通过自动将其设置为 12:00。

SimpleDateFormat dfFull = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String todayDate = dfFull.parse("2014-06-06 00:00:00");

today = dfFull.format(todayDate);
System.out.println(today);

为什么会这样:

2014-06-06 12:00:00

12:00:00 是问题所在

最佳答案

这是因为 hh 表示 12 小时格式的小时。您需要使用 HH 来代替。

SimpleDateFormat dfFull = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

看看 docs了解更多信息。

另外,顺便说一下,您的代码中有一个拼写错误。

SimpleDateFormat dfFull = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date todayDate = dfFull.parse("2014-06-06 00:00:00"); // todayDate must be of type Date and not String
String today = dfFull.format(todayDate); // today should be of type String
System.out.println(today);

关于Java日期格式奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21524759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com