java get date marker field(am/pm)

后端 未结 5 1320
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 04:07

I need to get the field AM/PM in date object. How can i get it?

This is my code.

String startTime =\"01:05 PM\";
 SimpleDateFormat sdf = new SimpleDa         


        
5条回答
  •  不知归路
    2021-01-12 04:51

    Calendar can also do

    Calendar cal = Calendar.getInstance();
    cal.setTime(st);
    String meridiem = cal.getDisplayName(Calendar.AM_PM, Calendar.SHORT, Locale.getDefault())
    

    meridiem now equals "PM" based on your code.

提交回复
热议问题