Mad*_*mer 10
首先解析String为LocalTime...
String timeValue = "8:32:00 PM";
DateTimeFormatter parseFormat = new DateTimeFormatterBuilder().appendPattern("h:mm:ss a").toFormatter();
LocalTime localTime = LocalTime.parse(timeValue, parseFormat);
Run Code Online (Sandbox Code Playgroud)
然后格式化结果......
DateTimeFormatter outputFormat = new DateTimeFormatterBuilder().appendPattern("H:mm:ss").toFormatter();
String formatted = localTime.toString(outputFormat);
System.out.println(formatted);
Run Code Online (Sandbox Code Playgroud)
哪个会输出 20:32:00
请记住,值LocalTime和格式是两个独立的概念,你不能影响LocalTime对象本身的"格式" ,你只能将值的概念转换为String表示(通过格式化程序)
| 归档时间: |
|
| 查看次数: |
7269 次 |
| 最近记录: |