Fork me on GitHub
#java
<
2021-12-06
>
yubrshen03:12:35

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!

seancorfield03:12:31

@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=>

👀 1
🙏 1
yubrshen04:12:36

@seancorfield Thanks. I wonder why there is such strange arrangement?

seancorfield04:12:06

What wrapper library are you using?

yubrshen04:12:38

[java-time :as t] clojure.java-time/clojure.java-time {:mvn/version "0.3.3"}

emccue04:12:29

if i could start from scratch i would use that - more 1-1 with java’s api

🙏 1
seancorfield04:12:39

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.

seancorfield04:12:30

At least you can always mix'n'match:

user=> (require '[java-time :as t])
nil
user=> (.getMinute (t/local-date-time))
47
user=>