gpt4 book ai didi

java - 我需要将时间显示为 24 小时格式到 12(上午/下午)小时格式

转载 作者:行者123 更新时间:2023-11-29 18:52:40 26 4
gpt4 key购买 nike

<分区>

在这段代码中,在 12:01:00 的情况下显示错误的时间,它显示 12:00 AM 但正确的时间是 12:00 PM:

private static final String sourceFormat = "hh:mm:ss";
private static final String targetFormat = "hh:mm a";

public static String convertTimeFormat(String dateStr) {

if (dateStr.equals("")) {
return "";
}
Log.d("date", dateStr + "---" + sourceFormat + "---" + targetFormat);
SimpleDateFormat form = new SimpleDateFormat(sourceFormat);
Date date = null;
try {
date = form.parse(dateStr);
} catch (Exception e) {
e.printStackTrace();
}
SimpleDateFormat postFormater = new SimpleDateFormat(targetFormat);
String newDateStr = postFormater.format(date);
Log.d("Lead Response", newDateStr);
return newDateStr;
}

非常感谢您在这件事上的时间和帮助。

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