• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the DateFormat.MEDIUM format's format?  RSS feed

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I know that I could do something like this:


and from the output, I can deduce what the DateFormat.MEDIUM format is.

What I'd like to do though, is just list what the format is, for each of my supported locales. I want output as follows:

en_CA = d-MMM-yyyy

Is this possible somehow?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the SimpleDateFormat implementation of DateFormat and then call its toPattern or toLocalizedPattern method.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joanne, this is what I came up with :


It produces:
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great - note that DateFormat.getDateInstance is only specified to return a DateFormat object, so any class that extends DateFormat could be returned
i.e. this is not guaranteed to work in every JRE - you could get a ClassCastException in some versions from this line
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!