我有这个时间。晚上 8:32:00。如何将其转换为 24 小时 Joda-Time本地时间格式? Joda-Time 库中没有时间转换器
最佳答案
首先将 String
解析为 LocalTime
...
String timeValue = "8:32:00 PM";
DateTimeFormatter parseFormat = new DateTimeFormatterBuilder().appendPattern("h:mm:ss a").toFormatter();
LocalTime localTime = LocalTime.parse(timeValue, parseFormat);
然后格式化结果...
DateTimeFormatter outputFormat = new DateTimeFormatterBuilder().appendPattern("H:mm:ss").toFormatter();
String formatted = localTime.toString(outputFormat);
System.out.println(formatted);
这将输出20:32:00
记住,LocalTime
的值和格式是两个独立的概念,你不能影响LocalTime
对象本身的“格式”,你只能翻译String
表示形式的值的概念(通过格式化程序)
关于java - Joda-Time 字符串到 LocalTime 24 小时等效值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24857104/