I am setting some default hardcoded times. I am looking to hardcode 6pm as my default time. I have the code as follows:
Calendar mDate = Calendar.getInstance();
SimpleDateFormat mDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy");
mydatetime = mDate.getTime();
For mydatetime I was looking to hardcode 5pm as the date time, but not sure how to go about it? any ideas?
You can set time to Calendar
object as below:
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
Use Calendar.HOUR_OF_DAY
for 24 hour format.
Or: Calendar.HOUR
for 12 hour format with calendar.set(Calendar.AM_PM, Calendar.PM);
for setting AM or PM.
In your case you can use as below:
Calendar mDate = Calendar.getInstance();
mDate.set(Calendar.HOUR, 5);
mDate.set(Calendar.MINUTE, 0);
mDate.set(Calendar.AM_PM, Calendar.PM);
SimpleDateFormat mDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy, hh:mm a");
mydatetime = mDate.getTime();