How to convert Local time to am/pm time format using JodaTime?

為{幸葍}努か 提交于 2019-12-19 07:51:51

问题


I'm very new to Joda api and I have the call like this:

 LocalTime time = new LocalTime("13");

it prints as:13:00:00.000.

I wish I could display it like this: 1:00 PM.

How I can achieve that?

Thanks in advance


回答1:


Try the following:

DateTimeFormatter builder = DateTimeFormat.forPattern("hh:mm:ss.SSa");



回答2:


I did this:

    LocalTime time = new LocalTime("13");    
    DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm a");
    String str = fmt.print(time);

And got this output for str:

"1:00 PM"


来源:https://stackoverflow.com/questions/25646048/how-to-convert-local-time-to-am-pm-time-format-using-jodatime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!