arielnmz
arielnmz

Reputation: 9155

How to format a localized date without specifying a localized pattern?

I have this pattern MMMM YYYY, but my locale is es_MX so I get the infamous java.lang.IllegalArgumentException: Unknown pattern character 'Y' exception.

The problem is that I get the exception right at the constructor:

new SimpleDateFormat(pattern, locale);

So I can't create a new instance with just the Locale (so then I could apply a locale-less pattern with applyPattern) nor apply a Locale after instatiation so I could then call toLocalizedPattern() so that it returns the localized version of MMMM YYYY.

Upvotes: 0

Views: 78

Answers (2)

Jigar Joshi
Jigar Joshi

Reputation: 240966

for year - pattern is yyyy not YYYY

is that so? I had this code working a few months ago and the case was never a problem. –

java 7 onwards supports Y and it represents week year - so this code likely to work without exception (not as expected though)

java 6 or prior doesn't support Y so it will fail to parse

Upvotes: 3

Wundwin Born
Wundwin Born

Reputation: 3475

The pattern yyyy lower case is for Year.

And YYYY upper case is for Week Year.

See API doc here

Upvotes: 2

Related Questions