I have a script at the moment that is always being passed the time in an AM PM format. But I do not know how to set the calendar with this time as it only accepts 24 hour format the way I have the code written. How would I convert the time to 24 hour or input a 12 hour format?
calendar.set(Calendar.HOUR_OF_DAY, HourValue);
calendar.set(Calendar.MINUTE, MinuteValue);
calendar.set(Calendar.SECOND, 0);
calendar.add(Calendar.MINUTE, -356);
http://developer.android.com/reference/java/util/Calendar.html#HOUR
calendar.set(calendar.HOUR,HourValue) , instead of HOUR_OF_DAY so if you give a 24 hour input it converts it into 12 hour format
0 for am and 1 for pm
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
c.set(Calendar.AM_PM, 1);
c.set(Calendar.HOUR, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, 00);
c.set(Calendar.MILLISECOND, 00);
int am_pm=c.get(Calendar.AM_PM);
String time=c.HOUR + ((am_pm==Calendar.AM)?"am":"pm"))
you can try the above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With