linux - java.text.ParseException: Unparseable date: "1901-01-01 00:00:00" -


this piece of code works correctly in windows, in 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         @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)         @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)         @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)         @ java.lang.reflect.method.invoke(method.java:606)         @ com.simontuffs.onejar.boot.run(boot.java:340)         @ com.simontuffs.onejar.boot.main(boot.java:166) caused by: java.text.parseexception: unparseable date: "1901-01-01 00:00:00"         @ java.text.dateformat.parse(dateformat.java:357)         ... 

if remove df.setlenient(false) line, windows output same, , linux exception disappears, linux output seems incorrect:

tue jan 01 00:14:44 cet 1901 

does know going on?

thanks

configuration:
windows: win7 + jdk1.7.0_71
linux: ubuntu + jdk1.7.0_60

edit: anolsi said daylight saving problem. date "2015-03-29 02:00:01" parse exception thrown, in windows , linux, because date doesn't exist in madrid (the time changed 2:00am 3:00am in madrid day). correct behaviour linux one. windows jdk should throw exception.

that should related locale/timezone definition using.

as can check under http://www.timeanddate.com/time/change/spain/madrid?year=1901 specific time didn't exists on timezone, because dst (daylight saving time). should causing inconsistency.

if try instead 1901-02-01 00:00:00, instance, should work fine.

edit1: example allow changing , controlling timezone.

import java.text.simpledateformat; import java.text.dateformat; import java.util.locale; import java.util.timezone; import java.util.date;  public class mainclass {   public static void main(string[] args)   {     try {         dateformat df = new simpledateformat("yyyy-mm-dd hh:mm:ss", new locale("es", "es"));         df.settimezone(timezone.gettimezone("europe/madrid"));         df.setlenient(false);         date date = df.parse("1901-01-01 00:00:00");         system.out.println(date);     } catch(exception ex){         ex.printstacktrace();     }    } } 

edit2: please take on article regarding timezones , offsets: https://stackoverflow.com/tags/timezone/info


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -