I am working in an app where i am displaying a DatePicker followed by a TimePicker.
Now as per my client requirement, I want to show the Datepicker and TimePicker based on the country name.
For example, If the country name is India, India's present Date and Time should be shown and if it USA, USA's present date and time should be shown.
I came across only one thread in stackoverflow regarding this and that too is unanswered.
Can you guys please help me in this !
My code for Date and Time Picker
private void datePicker() {
// Get Current Date
TextView mobileTxt = (TextView) findViewById(R.id.mobile);
String countryName = getCountryNameOfPhoneNumber((String) mobileTxt.getText());
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
date_time = dayOfMonth + "-" + (monthOfYear + 1) + "-" + year;
//*************Call Time Picker Here ********************
tiemPicker();
}
}, mYear, mMonth, mDay);
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
datePickerDialog.show();
}
private void tiemPicker() {
// Get Current Time
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
// Launch Time Picker Dialog
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour = hourOfDay;
mMinute = minute;
if (mHour <= c.get(Calendar.HOUR) && mMinute <= c.get(Calendar.MINUTE)) {
Toast.makeText(SoundRecord.this, "Please Select future time !", Toast.LENGTH_SHORT).show();
} else {
EditText et_show_date_time = (EditText) findViewById(R.id.et_show_date_time);
et_show_date_time.setText(date_time + " " + hourOfDay + ":" + minute);
}
}
}, mHour, mMinute, false);
timePickerDialog.show();
}
Kindly looking forward for some help!