This piece of code works correctly on Windows, but on Linux throws java.text.ParseException:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", new Locale("es", "ES")); df.setLenient(false); Date date = df.parse("1901-01-01 00:00:00"); System.out.println(date);
Windows output:
Tue Jan 01 00:00:00 CET 1901
Linux output:
Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.simontuffs.onejar.Boot.run(Boot.java:340) at com.simontuffs.onejar.Boot.main(Boot.java:166) Caused by: java.text.ParseException: Unparseable date: "1901-01-01 00:00:00" at java.text.DateFormat.parse(DateFormat.java:357) ...
If you delete the df.setLenient(false) , the Windows output will be the same and the Linux exception will disappear, however, the Linux output looks incorrect:
Tue Jan 01 00:14:44 CET 1901
Does anyone know what is going on?
thanks
Configuration:
Windows: Win7 + jdk1.7.0_71
Linux: Ubuntu + jdk1.7.0_60
EDIT: As anolsi said, this is a problem with summer savings. With the date "2015-03-29 02:00:01", a parsing exception is selected on Windows and Linux because this date does not exist in Madrid (the time was changed from 2:00 to 3:00 in Madrid that day). Therefore, the correct behavior is Linux. Windows JDK should throw an exception.
source share