Srinivasan Srinivasan - 1 year ago 139
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);

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download