Good Morning!
morning
π
Morning
Happy tiny chocolate day
Good morning π
Morning!
Morning
morning
Β‘mΓ₯nmΓ₯nΒ‘
Morning
Morning All π
Does anyone have a quick / reliable way to make #inst "2020-12-01T12:00:00"
have a timezone, so that it can be formatted using the date / time formatting functions in clojure.java-time?
I get a type error when I try to do this:
(jt/format "dd/MM/yyyy" #inst "2020-12-01T12:00:00")
and I am pretty sure that this is because a bare Clojure Instant has no timezone info as it is assumed to be UTC
(above, jt/
is as a result of (require '[java-time :as jt])
)
where your datetime is dt
, (str dt "Z")
i know, def a case of 'just because you can doesn't mean you should' hahaha
quick and dirty but then it's utc/z
In the spirit of full disclosure, this is the solution I have (now):
(jt/format "dd/MM/yyyy" (.atZone (.toInstant #inst "2020-12-01T12:00:00") (jt/zone-id)))
but i would like something less unwieldy and less Java-y if it's possible.
(assume that #inst "2020-12--1T12:00:00"
would actually be passed in as a value / input)
Morning
with the obvious caveat that this works IIF the format is exactly as above lol in practice i'd parse it and then coerce it using a lib and a threading form
With tick: (t/in #inst "2020-12-01T12:00:00" (t/zone "Europe/London"))
You're a monster :D
@maleghast there's 2 things you might want to have happen here:
1. You want to have 2020-12-01T12:00:00 in the target timezone. E.g. a shift into Tokyo would be "2020-12-01T12:00+09:00[Asia/Tokyo]"
2. You want to shift from UTC to the target timezone. E.g. a shift into Tokyo would be "2020-12-01T21:00+09:00[Asia/Tokyo]"
@dominicm - Thanks, that's very cool π (I had forgotten about tick)
Here's the code for (1). But assuming that your inst is an inst, you don't want this:
(let [dt #inst "2020-12-01T12:00:00"]
(cljc.java-time.zoned-date-time/of
(t/date dt)
(t/time (t/instant dt))
(t/zone "Asia/Tokyo")))
The first snippet I produced is probably what you want.Thanks very much, have stored that away for myself and passed on the knowledge to the person who was having issues. π
Technically, an instant has no timezone because itβs the number of seconds elapsed since the epoch moment (Jan 1st 1970 at 00:00:00 UTC), which is the same number of seconds anywhere