Variance between `(js/Date.)` in my app and in the shadow-cljs REPL

I’m asking in the beginners’ section in case this is quite obvious to most of you. When I invoke (js/Date.) in the REPL (I am using shadow-cljs) I get today’s date according to Universal Control Time, and when I do so in my app I get today’s date according to my local timezone.

Anyone care to offer an explanation as to why this is so?

Thank you for reading,

I tried in REPL:

> (println (js/Date.))
#inst "2020-11-19T06:52:42.576-00:00"
> (js/console.log (js/Date.))

it displays in Chrome:

#inst "2020-11-19T06:52:42.576-00:00"
Thu Nov 19 2020 14:53:39 GMT+0800 (China Standard Time)

appears that println formats time internally so it’s UTC time.

First thing to point out is that the dates aren’t different, it’s just how they’re printing. Dates have no zone info.

The default print for the browser is local wall clock, and shadow repl is utc


Thank you for this great way easily to demonstrate the variance between ‘REPL-time’ and ‘Broswer-time’ which I was pointing out.

Thanks for that clue, that it’s simply their output which is set either to the local time zone or to UTC.

Curious if it’s possible to set shadow’s time zone to local time instead of UTC.

There is no such thing as “shadow’s time zone”. When printing a javascript Date the default implementation prints the output in UTC format. It is done this way to be more portable between CLJ and CLJS and because it “makes sense”.

When looking at it on the browser console or just calling .toString you get the default representation the browser choses which is in your local timezone.

There is no such thing as REPL-time or Browser-time. They are the exact same times just printed differently. You cannot modify the REPL representation but if it bothers you can use (.toLocaleString the-date) or (.toString the-date) instead.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.