1

I want to format correctly according to the device configuration a date, but I want to force YYYY instead of YY. My current code is the following:

java.text.DateFormat dateFormat = android.text.format.
                DateFormat.getDateFormat(context);
String fDate = dateFormat.format(date);

For example, if dateFormat is dd/mm/yy it must become dd/mm/yyyy, if dateFormat is yy/mm/dd it must become yyyy/mm/dd and so on.

Bob
  • 381
  • 4
  • 12
  • Are you trying to programmatically change the formatting for the device or just your app. As date formatting is related to locale/language see: https://stackoverflow.com/q/2900023/295004 – Morrison Chang May 21 '18 at 19:30
  • @MorrisonChang just for my app – Bob May 21 '18 at 20:19

1 Answers1

0

you can use below code, it will give you the date in your format:

DateFormat.forPattern("MM/dd/yyyy").print(new LocalDate())
Bret Hawker
  • 99
  • 1
  • 11