1

it's 15:51 here.

Well, in UTF it's 13:51. I'm trying to unparse the current local hours by the help of the cljs-time library.

Here's the non-local approach:

(require [cljs-time.format :as tf]
         [cljs-time.coerce :as tc])

(tf/unparse (tf/formatter "HH") (tc/from-date (js/Date.)))
;; 13 

Unfortunately the following produces the same result and not the desired 15:

(tf/unparse-local (tf/formatter-local "HH") (tc/from-date (js/Date.)))

Does anybody know, what's going on here?

1 Answer 1

2

By default, cljs-time works via goog.date.UtcDateTime, which returns UTC hours and minutes.

unparse-local and formatter-local just remove the time zone field from the format string. They do not affect the time zone.

To work with the local (default) time, goog.date.DateTime, you can use cljs-time.core/to-default-time-zone:

(require '[cljs-time.core :as time]
         '[cljs-time.format :as fmt])

(tf/unparse (tf/formatter "HH") (time/to-default-time-zone (js/Date.)))

This should return your local time in hours.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.