2

I have to represent date in different locales.
Some locale standards should show as dd/MM/yyyy, some - MM/dd/yyyy.
I know that I can use DateFormat.getDateInstance(DateFormat.SHORT) to achieve result like I want, but not completely.

DateFormat.getDateInstance(DateFormat.SHORT) will formate date similar to dd/MM/yy, while I need dd/MM/yyyy (YEAR to show like 2016, not like 16).

Is there a way to achieve what I want?

Vladyslav Matviienko
  • 10,610
  • 4
  • 33
  • 52

1 Answers1

0

getDateInstance(DateFormat.SHORT)

returns shorter date

getDateInstance(DateFormat.LONG)

returns longer format .

SHORT is completely numeric, such as 12.13.52 or 3:30pm
LONG is longer, such as January 12, 1952 or 3:30:32pm

You can also set the time zone on the format if you wish. If you want even more control over the format or parsing, (or want to give your users more control), you can try casting the DateFormat you get from the factory methods to a SimpleDateFormat. This will work for the majority of countries; just remember to put it in a try block in case you encounter an unusual one.

For more Reference

  1. SimpleDateFormat and locale based format
Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198