gpt4 book ai didi

Java - SimpleDateFormat 解析 12 :19:00 to 00:19:00

转载 作者:搜寻专家 更新时间:2023-11-01 01:22:35 25 4
gpt4 key购买 nike

我正在尝试解析一个字符串,但输出看起来不正确:下面是我的代码。

public static void main(String[] args){      
Date startDate = new Date();
DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss");

try {
startDate = (Date) formatter.parse("07.10.2012 12:19:24");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("Formatted Date " + startDate.toString());
}

程序输出:
格式化日期 Sun Oct 07 00:19:24 IST 2012

预期输出:
格式化日期 Sun Oct 07 12:19:24 IST 2012

最佳答案

您可能想使用 24 小时格式而不是 12 小时格式...

H Hour in day (0-23) Number 0

h Hour in am/pm (1-12) Number 12

是的,格式化字符区分大小写。

关于Java - SimpleDateFormat 解析 12 :19:00 to 00:19:00,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13245944/

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