Why parsing date in clojure shifts the result 2 hours back -


clojure code

(def fmt (java.text.simpledateformat. "yyyy-mm-dd")) #'user/fmt user=> (.parse fmt "2015-07-10") #inst "2015-07-09t22:00:00.000-00:00" 

analogous java code:

public class datefmt {     public static void main(string[] args) throws parseexception {         final simpledateformat sdf = new simpledateformat("yyyy-mm-dd");         final date date = sdf.parse("2015-07-10");          system.out.println(date);     } } 

while java code prints: fri jul 10 00:00:00 cest 2015 (which expect), clojure shifts 2 hours back?

there's difference between clojure's instant , java's date, big piece being time offset optional.

unlike rfc3339:

  • we parse timestamp format
  • timestamp can elide trailing components
  • time-offset optional (defaults +00:00)

so, clojure's time tied utc, whereas java tied local timezone is.

the times equivalent, since you're two hours ahead of utc.

if want clojure output match java, have instruct simpledateformat instance read time in utc instead.

(def fmt   (let [format (java.text.simpledateformat. "yyyy-mm-dd")]     (.settimezone format (java.util.timezone/gettimezone "utc"))     format)) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -