Question: How to get the value of minutes of hour from an object of java.time.LocalDateTime?
I have computed a result of the following:
(:date-time (first result))
;; => #object[java.time.LocalDateTime 0x76414a16 "2021-07-31T00:00:45.582"]
I’m having hard to time to get the minutes within hour from it.
Using (java.time/as (:date-time (first result))), I’m able to get most of the components, year, month, day, hour, except, minute, second, and millis. With (java.time/as-map (:date-time (first result))), I can get the following:
<file:///C:/Users/yshen/OneDrive%20-%20San%20Francisco%20Bay%20Area%20Rapid%20Transit%20District/Documents/my_setup/projects/dev/EtaReport-study/EtaReport-code-study.html#,code--2|#>
;; => {:proleptic-month 24258,
:julian-day 2459427,
:week-based-year 2021,
:hour-of-am-pm 0,
:nano-of-second 582000000,
:era 1,
:rata-die 738002,
:micro-of-day 45582000,
:day-of-week 6,
:hour-of-day 0,
:month-of-year 7,
:milli-of-second 582,
:micro-of-second 582000,
:day-of-month 31,
:year 2021,
:day-of-year 212,
:day-of-quarter 31,
:year-of-era 2021,
:nano-of-day 45582000000,
:second-of-minute 45,
:second-of-day 45,
:modified-julian-day 59426,
:week-of-week-based-year 30,
:milli-of-day 45582,
:quarter-of-year 3}
from :second-of-minute, I can get the second, from :milli-of-second, the millis but the value of minute is still a mystery.
Please help. I must have missed something obvious. Thanks!@yubrshen It's easy enough to do with Java interop, instead of using a Clojure wrapper:
user=> (def now (java.time.LocalDateTime/now))
#'user/now
user=> now
#object[java.time.LocalDateTime 0x7e8e8651 "2021-12-05T19:10:26.925339"]
user=> (.getMinute now)
10
user=>@seancorfield Thanks. I wonder why there is such strange arrangement?
What wrapper library are you using?
[java-time :as t] clojure.java-time/clojure.java-time {:mvn/version "0.3.3"}
cljc java time has get-minute https://github.com/henryw374/cljc.java-time/blob/master/src/cljc/java_time/local_date_time.clj#L54
if i could start from scratch i would use that - more 1-1 with java’s api
Yeah, we use clojure.java-time at work but we also use plain Java interop. If cljc.java-time had existed when we moved from clj-time, we'd have probably gone with it.
At least you can always mix'n'match:
user=> (require '[java-time :as t])
nil
user=> (.getMinute (t/local-date-time))
47
user=>