Srinivasan Srinivasan - 7 months ago 68
Java Question

java get date marker field(am/pm)

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 SimpleDateFormat("hh:mm aa");

Date st = sdf.parse(startTime);


You could use a Calendar.

Calendar cal = Calendar.getInstance();
if (cal.get(Calendar.AM_PM) == Calendar.PM) {

Make sure you don't have a time zone mismatch when you do this.