In Android all Date objects are given in this type of date format "Mon Dec 03 00:13:21 GMT+05:30 2018"
when you convert it with SimpleDateFormat
.
Is there any possibility of getting a Date object in the "dd-mm-yyyy"
format in Android?
In Android all Date objects are given in this type of date format "Mon Dec 03 00:13:21 GMT+05:30 2018"
when you convert it with SimpleDateFormat
.
Is there any possibility of getting a Date object in the "dd-mm-yyyy"
format in Android?
You could set the pattern on a SimpleDateFormat and format the date:
new SimpleDateFormat("dd-mm-yyyy").format(new Date());
You could convert Strings
into Dates
as the following:
String pattern = "dd-mm-yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String strDate = simpleDateFormat.format(new Date());//firstly get formatted str
Date newDate = simpleDateFormat.parse(strDate);//then get date object with wanted format