java get date marker field(am/pm)

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

    Please try this

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss_aa");
        Calendar cal = Calendar.getInstance();
        Log.d("Time", ""+dateFormat.format(cal.getTime()));
        int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
        System.out.println("time => " + namesOfDays[day-1]+"_"+dateFormat.format(cal.getTime()));
    

提交回复
热议问题