java.text.SimpleDateFormat#parse has different behaviour between Scala and Clojure -


i'm trying assign pdt string java.util.date using simpledateformat.

scala, gives me right format pdt (utc-07:00), or without setting timezone os timezone "america/los_angeles".

scala> import java.util.timezone import java.util.timezone  scala> import java.util.date import java.util.date  scala> import java.text.simpledateformat import java.text.simpledateformat  scala> timezone.getdefault res0: java.util.timezone = sun.util.calendar.zoneinfo[id="america/los_angeles",offset=-28800000,dstsavings=3600000,usedaylight=true,transitions=185,lastrule=java.util.simpletimezone[id=america/los_angeles,offset=-28800000,dstsavings=3600000,usedaylight=true,startyear=0,startmode=3,startmonth=2,startday=8,startdayofweek=1,starttime=7200000,starttimemode=0,endmode=3,endmonth=10,endday=1,enddayofweek=1,endtime=7200000,endtimemode=0]]  scala> val df = new simpledateformat("yyyy-mm-dd't'hh:mm:ssxxx") df: java.text.simpledateformat = java.text.simpledateformat@fe8c5ede  scala> df.parse("2017-10-28t23:59:59-07:00") res1: java.util.date = sat oct 28 23:59:59 pdt 2017 

but clojure parses date in utc format (:utc-00:00),

without .settimezone,

aws-creds.core=> (import 'java.util.timezone) java.util.timezone  aws-creds.core=> (timezone/getdefault) #object[sun.util.calendar.zoneinfo 0x28ce2a1 "sun.util.calendar.zoneinfo[id=\"america/los_angeles\",offset=-28800000,dstsavings=3600000,usedaylight=true,transitions=185,lastrule=java.util.simpletimezone[id=america/los_angeles,offset=-28800000,dstsavings=3600000,usedaylight=true,startyear=0,startmode=3,startmonth=2,startday=8,startdayofweek=1,starttime=7200000,starttimemode=0,endmode=3,endmonth=10,endday=1,enddayofweek=1,endtime=7200000,endtimemode=0]]"]  aws-creds.core=> (import 'java.util.date) java.util.date  aws-creds.core=> (import 'java.text.simpledateformat) java.text.simpledateformat  aws-creds.core=> (let [df (new simpledateformat "yyyy-mm-dd't'hh:mm:ssxxx" )]             #_=>   (print (.parse df "2017-10-28t23:59:59-07:00"))) #inst "2017-10-29t06:59:59.000-00:00"nil 

same behaviour .settimezone america/los_angeles,

aws-creds.core=> (let [df (new simpledateformat "yyyy-mm-dd't'hh:mm:ssxxx" )]             #_=>   (.settimezone df (timezone/gettimezone "america/los_angeles"))             #_=>   (print (.parse df "2017-10-28t23:59:59-07:00"))) #inst "2017-10-29t06:59:59.000-00:00"nil 

which strange, since in both cases i'm using java.text.simpledateformat. curious why simpledateformat#parse scala stores date in pdt format while clojure in utc format?

looks clojure repl prints dates in utc.

if call tostring() on date, prints date scala repl (which believe implicitly calls tostring when printing objects) does, , in system time zone:

user=> (let [df (new simpledateformat "yyyy-mm-dd't'hh:mm:ssxxx" )]   #_=>   (print (.tostring (.parse df "2017-10-28t23:59:59-07:00")))) sat oct 28 23:59:59 pdt 2017nil 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -