What is the date format to get only hours in 12-hours
format from this time
Thu Oct 20 13:12:00 GMT+02:00 2011
using this code
Date eventDate = tempAppointments.get(i).mStartDate
System.out.println(eventDate.toString());
// date pattern
DateFormat df = new SimpleDateFormat("hh:'00' a");//output : Wed Nov 09 11:00:00 GMT+02:00 2011
// get the start date with new format (pattern)
String hours = df.format(tempAppointments.get(i).mStartDate.getDay());
System.out.print(hours);//output: 02:00 AM
return hours as
02:00 AM
but for the given time. it must be 02:00 PM
. why ?
I'm not sure why you are passing date.getDay()
(which is deprecated, by the way) into the formatter if you want the hour part.
Try this:-
Date date = new Date();
System.out.println("Date: " + date);
DateFormat df = new SimpleDateFormat("hh:'00' a");
String hour = df.format(date);
System.out.println("Hour: " + hour);
The output:
Date: Sat Nov 19 17:57:05 CST 2011
Hour: 05:00 PM
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