gpt4 book ai didi

java 日期格式错误响应

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

我正在使用此函数将日期转换为显示格式。但返回错误的响应。

date = converDateFormate("yyyy/MM/dd hh:mm:ss", "MM/dd/yyyy hh:mm a","2013/11/28 12:23:28");

Wrong Response: 11/28/2013 12:23 **AM**

Right Response: 11/28/2013 12:23 **PM** (how can I get this response)


public static String converDateFormate(String oldpattern,
String newPattern, String dateString) throws ParseException {
if (dateString != null) {
SimpleDateFormat sdf = new SimpleDateFormat(oldpattern);
Date testDate = null;
testDate = sdf.parse(dateString);
SimpleDateFormat formatter = new SimpleDateFormat(newPattern);
String newFormat = formatter.format(testDate);
System.out.println("" + newFormat);
return newFormat;
} else {
return "";
}
}

最佳答案

看看here在“中午和午夜的困惑”。如果您的输入采用 24 小时格式,则需要在模式中使用 HH:mm:ss

关于java 日期格式错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20264785/

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