java get date marker field(am/pm)

后端 未结 5 1370
没有蜡笔的小新
没有蜡笔的小新 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 05:02

    use this..

    String getTime(String milliseconds) {
    
        String time = "";
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(Long.parseLong(milliseconds));
    
        time = cal.get(Calendar.HOUR) + " : " + cal.get(Calendar.MINUTE);
    
        if(cal.get(Calendar.AM_PM)==0)
            time=time+" AM";
        else
            time=time+" PM";
    
        return time;
    
    }
    

提交回复
热议问题