Reputation: 10778
Is there any way to reformat the datePicker so that instead of getting "mm/dd/yyyy" you can get "dd/mm/yyyy" or even "dd/mm/yy"
This is my current code.
import android.app.Activity;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.app.DatePickerDialog.OnDateSetListener;
import java.util.Calendar;
/**
* Created by MOS182 on 7/21/13.
*/
public class AddReminder extends Activity {
TextView Title, Amount, PaymentDate, ReminderDate, ReminderTime;
EditText eTitle, eAmount, ePaymentDate, eReminderDate, eReminderTime;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.reminders_dialog);
initializeVariables();
ePaymentDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//To show current date in the datepicker
Calendar mcurrentDate = Calendar.getInstance();
int mYear = mcurrentDate.get(Calendar.YEAR);
int mMonth = mcurrentDate.get(Calendar.MONTH);
int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker;
mDatePicker = new DatePickerDialog(AddReminder.this, new OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
/* Your code to get date and time */
selectedmonth = selectedmonth + 1;
ePaymentDate.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
}
}, mYear, mMonth, mDay);
mDatePicker.setTitle("Select date");
mDatePicker.show();
}
});
}
private void initializeVariables()
{
Title = (TextView) findViewById(R.id.tvTitle);
Amount = (TextView) findViewById(R.id.tvAmount);
PaymentDate = (TextView) findViewById(R.id.tvPaymentDate);
ReminderDate = (TextView) findViewById(R.id.tvReminderDate);
ReminderTime = (TextView) findViewById(R.id.tvReminderTime);
eTitle = (EditText) findViewById(R.id.etTitle);
eAmount = (EditText) findViewById(R.id.etAmount);
ePaymentDate = (EditText) findViewById(R.id.etPaymentDate);
eReminderDate = (EditText) findViewById(R.id.etReminderDate);
eReminderTime = (EditText) findViewById(R.id.etReminderTime);
}
}
This is what is currently displayed when I run my code and select the ePaymentDate field.
Upvotes: 0
Views: 1906
Reputation: 2405
The picker take the date format chosen by the user, which means you don't really have to format it, as probably the user enjoys the most to see the format he's used to.
I just tested a code and on my phone, where I have the date in (dd/mm/yyyy) format, so the picker shows the same format; in emulator, I've put the date in mm/dd/yyyy format, so the picker displays the same.
So there is no method to set the display format.
But if you still really want to display a specific format, then refer to this link, there is an elaborate way to show the date in the desired format, but with changes in the original code.
Upvotes: 2