Illegal pattern character 'Y' on Ubuntu
Asked Answered
T

2

13

I use this pattern SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); in windows and it works, but when try on Ubuntu 10.04 it show an exception play.exceptions.JavaExecutionException: Illegal pattern character 'Y'.

I search for solution for this and found the year pattern must be change to lower-case: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); and it works.

Can anyone can tell me the reason behind this why in Windows works but in Ubuntu didn't work if I use 'Y' instead of 'y'?

Note:

  1. Play-1.2.3
  2. JRE:
    1. Windows: java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b05) Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)
    2. Ubuntu: java version "1.6.0_31" Java(TM) SE Runtime Environment (build 1.6.0_31-b04) Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
  3. Windows 7
  4. Ubuntu 10.04

Update 24/05/2012

After I check again in my system, there is 3 JRE and my windows using JRE1.7 for default. But for Play I set running using JRE1.6.

Tritanopia answered 14/5, 2012 at 1:37 Comment(1)
Because the Ubuntu implementation follows the API documentation? Without digging into the source, this may just be an opinion answer, but someone else may know more.Mariner
T
21

I search for SimpleDateFormat and got the doc from oracle.

Works in my windows because I set the default JRE to 1.7 but still running using JRE1.6 for the Play Framework.

enter image description here

Works on Windows because of this, JRE1.7 has added 'Y' pattern for Week year and in JRE1.6 there is no pattern for this.

Tritanopia answered 24/5, 2012 at 4:39 Comment(0)
H
14

Y is not an valid pattern. y is.

As per the docs:

Letter   Date or Time Component     Presentation    Examples
G        Era designator             Text            AD
y        Year                       Year            1996; 96
M        Month in year              Month           July; Jul; 07
w        Week in year               Number          27
...

I don't know why Y would work in windows, but it is not documented. y is the correct one. And the safest.

Hardy answered 14/5, 2012 at 1:48 Comment(2)
Is it maybe because the different JRE that I use? For Windows I'm using JRE from Oracle but not sure if my Ubuntu using same JRE, because another person installing for me.Tritanopia
@Tritanopia - run java -versionFishery

© 2022 - 2024 — McMap. All rights reserved.