gpt4 book ai didi

java - 字符串到日期转换java结果不正确

转载 作者:行者123 更新时间:2023-12-02 03:24:18 24 4
gpt4 key购买 nike

我正在尝试将字符串形式的日期转换为日期

我的代码:

String dtStart = passedDate+" "+passedTme; // here my time is : 28/08/16 2:00 pm
System.out.println(dtStart);
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm a");
try {
Date date = format.parse(dtStart);
System.out.println(date); // and result output is : Fri Aug 28 00:00:00 GMT+05:30 16
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

以上获取的是 28/08/16 2:00 pm 并返回 Fri Aug 28 00:00:00 GMT+05:30 16

任何人都可以指出为什么我的输出在这里不正确?

已解决所需的格式是这样的:SimpleDateFormat("dd/MM/yy h:mm a")

最佳答案

anyone can point out why my output is not correct here

您设置了 yyyy,但传递了 16 作为年份。要么通过 4 位数年份,要么修正您的模式。

关于java - 字符串到日期转换java结果不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39185336/

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