gpt4 book ai didi

java - 显示无法解析的日期 : "09:30 AM" (at offset 6) in java android

转载 作者:行者123 更新时间:2023-12-01 06:04:22 27 4
gpt4 key购买 nike

当我将参数传递为“09:30 AM”时,它会在 android 中返回异常显示无法解析的日期:“09:30 AM”(偏移量 6)

 public static String convertTo24Hour (String now){
String time24="";
try {
SimpleDateFormat inFormat = new SimpleDateFormat("hh:mm a");
SimpleDateFormat outFormat = new SimpleDateFormat("HH:mm");
time24 = outFormat.format(inFormat.parse(now));
} catch (Exception e) {
System.out.println("Exception : " + e.getMessage());
}
return time24;
}

最佳答案

试试这个

public static String convertTo24Hour (String now){
String time24="";
try {
SimpleDateFormat inFormat = new SimpleDateFormat("hh:mm a",Locale.getDefault());
SimpleDateFormat outFormat = new SimpleDateFormat("H:mm", Locale.getDefault());
time24 = outFormat.format(inFormat.parse(now));
} catch (Exception e) {
System.out.println("Exception : " + e.getMessage());
}
return time24;
}

根据您的需要更改区域设置。希望这有帮助..

关于java - 显示无法解析的日期 : "09:30 AM" (at offset 6) in java android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48017846/

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