Clojure - Get hour only from Time String -
i have time string "2017-08-30 09:01:48". there way round time nearest hour , return hour?
so if time "2017-08-30 09:01:48" return 9
if time "2017-08-30 09:51:48" return 10
i looked @ library clj-time couldn't see in there me
any appreciated?
clj-time thin wrapper joda time library. can use methods of underlying java objects perform common date manipulations.
for rounding hour, can access hour datetime.property , use api round nearest hour follows:
(require '[clj-time.format :as tf]) (-> (tf/parse "2017-08-30 09:01:48") .hourofday .roundhalfceilingcopy .gethourofday) there several rounding methods (roundceilingcopy, roundhalffloorcopy, etc.) choose from, depending on exact case.
note also, don't need specify formatter, date string in iso8601 format.
Comments
Post a Comment