How Do I Set Custom Date In Android
How do i set the date to 25 -12(december)- current year. eg. I am using this code public static Calendar defaultCalendar() { Calendar currentDate = Calendar.getInstance();
Solution 1:
Something like this should work:
publicstatic Calendar defaultCalendar() {
Calendar currentDate = Calendar.getInstance();
currentDate.set(currentDate.get(Calendar.YEAR),Calendar.DECEMBER,25);
return currentDate;
}
Solution 2:
You're trying to add 12 months, instead of setting the month to December (which is month 11, because the Java API is horrible). You want something like:
publicstatic Calendar defaultCalendar() {
Calendar currentDate = Calendar.getInstance();
currentDate.set(Calendar.MONTH, 11); // Months are 0-based!
currentDate.set(Calendar.DAY_OF_MONTH, 25); // Clearer than DATEreturn currentDate;
}
Solution 3:
Use this it found very usefull to me though :
Take a look at SimpleDateFormat
.
The basics for getting the current time in ISO8601 format:
DateFormatdf=newSimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
Stringnow= df.format(newDate());
For other formats:
DateFormatdf=newSimpleDateFormat("MMM d, yyyy");
Stringnow= df.format(newDate());
or
DateFormatdf=newSimpleDateFormat("MM/dd/yy");
Stringnow= df.format(newDate());
EDit:
Check this link it will help you :
Post a Comment for "How Do I Set Custom Date In Android"