I have a problem with my Datapicker
i use the code for getting date,month & year shown below
DatePicker datePicker;
datePicker = (DatePicker) findViewById(R.id.dateselect);
int day = datePicker.getDayOfMonth();
int month= datePicker.getMonth() + 1;
int year = datePicker.getYear();
but when i print the date it shows the value 7 not 07 and for month it shows the value 2 not 02
I want these integer data in a date format ie; eg: 02-02-2013, 24-12-2013
Is there any possible way????
In the Data type Format dialog box, do one of the following: To format the control to show the date only, select the display style that you want in the Display the date like this list. To format the control to show the time only, select the display style that you want in the Display the time like this list.
The jQuery DatePicker plugin supports multiple Date formats and in order to set the dd/MM/yyyy Date format, the dateFormat property needs to be set. The following HTML Markup consists of a TextBox which has been made Read Only.
DateTimePicker allows you to define the text representation of a date and time value to be displayed in the DateTimePicker control. The format specified is achieved by the dateTimeFormat property. Default value of this property is M/d/yyyy h: mm tt.
You can format the date like this :
int day = datePicker.getDayOfMonth();
int month= datePicker.getMonth();
int year = datePicker.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
String formatedDate = sdf.format(calendar.getTime());
You can parse the String back to Date object by calling
Date date = sdf.parse(formatedDate);
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