1

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?

Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
  • No, a `Date` cannot have a format. What you see is the return value from its `toString` method. As an aside consider throwing away the long outmoded and notoriously troublesome `SimpleDateFormat` and friends, and adding [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) to your Android project in order to use `java.time`, the modern Java date and time API. It is so much nicer to work with. – Ole V.V. Dec 03 '18 at 10:46

2 Answers2

1

You could set the pattern on a SimpleDateFormat and format the date:

new SimpleDateFormat("dd-mm-yyyy").format(new Date());
Aaron
  • 3,764
  • 2
  • 8
  • 25
1

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
navylover
  • 12,383
  • 5
  • 28
  • 41