Dislpaying time in AM/PM format

Tutorials with advanced 'difficulty' and more Lines of Code.

Dislpaying time in AM/PM format

Postby rahul_kalidindi » Fri Apr 09, 2010 8:04 am

I am getting the time using a time picker and displaying the time in the text view using following code...

[syntax="java"] private TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(SendMail.this, "Your Appointment time is "+hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();
TextView datehid = (TextView)findViewById(R.id.timehidden);
datehid.setText(String.valueOf(hourOfDay)+ ":"+(String.valueOf(minute)));

}
};

Now, the issue is when i set the time as 8:00 pm then i get the time displayed as 20:0... I want to display the time as 8:00 pm... How can i do that???
Regards,
Rahul
rahul_kalidindi
Freshman
Freshman
 
Posts: 8
Joined: Tue Apr 06, 2010 8:41 am
Location: Visakhapatnam

Top

Re: Dislpaying time in AM/PM format

Postby Brocade » Sat Jul 03, 2010 2:57 pm

Code: Select all
TimePicker YourTimePicker = (TimePicker)this.findViewById(R.id.TimePicker01);
Calendar cal = Calendar.getInstance();
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), YourTimePicker.getCurrentHour(), YourTimePicker.getCurrentMinute());
String AMPM = cal.get(Calendar.AM_PM);


this is a bit excessive, but it explains Calendar.

-erin
Brocade
Freshman
Freshman
 
Posts: 4
Joined: Sat Jul 03, 2010 2:42 pm

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests