2016-09-29 194 views
1

這是15:51這裏。unparse js日期到本地時間字符串通過cljs-time

那麼,在UTF是13:51。我試圖在cljs-time library的幫助下解開當前的當地時間。

這裏的非本地方法:

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

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

不幸的是以下產生相同的結果,而不是所期望的15:

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

有誰知道,這是怎麼回事呢?

回答

1

默認情況下,通過goog.date.UtcDateTimecljs-time作品,它返回UTC小時和分鐘。

unparse-localformatter-local只是從格式字符串中刪除時區字段。它們不會影響時區。

與本地(默認值)時,goog.date.DateTime工作,你可以使用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.))) 

這應返回您的本地時間以小時爲單位。

相關問題