clj-time.format
Utilities for parsing and unparsing DateTimes as Strings.
Parsing and printing are controlled by formatters. You can either use one
of the built in ISO 8601 and a single RFC 822 formatters or define your own, e.g.:
(def built-in-formatter (formatters :basic-date-time))
(def custom-formatter (formatter "yyyyMMdd"))
To see a list of available built-in formatters and an example of a date-time
printed in their format:
(show-formatters)
Once you have a formatter, parsing and printing are straightforward:
=> (parse custom-formatter "20100311")
#<DateTime 2010-03-11T00:00:00.000Z>
=> (unparse custom-formatter (date-time 2010 10 3))
"20101003"
By default the parse function always returns a DateTime instance with a UTC
time zone, and the unparse function always represents a given DateTime
instance in UTC. A formatter can be modified to different timezones, locales,
etc with the functions with-zone, with-locale, with-chronology,
with-default-year and with-pivot-year.
Mappable
protocol
members
instant->map
(instant->map instant)
Returns a map representation of the given instant.
It will contain the following keys: :years, :months,
:days, :hours, :minutes and :seconds.
parse
(parse fmt s)
(parse s)
Returns a DateTime instance in the UTC time zone obtained by parsing the
given string according to the given formatter.
parse-local
(parse-local fmt s)
(parse-local s)
Returns a LocalDateTime instance obtained by parsing the
given string according to the given formatter.
parse-local-date
(parse-local-date fmt s)
(parse-local-date s)
Returns a LocalDate instance obtained by parsing the
given string according to the given formatter.
parse-local-time
(parse-local-time fmt s)
(parse-local-time s)
Returns a LocalTime instance obtained by parsing the
given string according to the given formatter.
unparse
(unparse fmt dt)
Returns a string representing the given DateTime instance in UTC and in the
form determined by the given formatter.
unparse-local
(unparse-local fmt dt)
Returns a string representing the given LocalDateTime instance in the
form determined by the given formatter.
unparse-local-date
(unparse-local-date fmt ld)
Returns a string representing the given LocalDate instance in the form
determined by the given formatter.
unparse-local-time
(unparse-local-time fmt lt)
Returns a string representing the given LocalTime instance in the form
determined by the given formatter.
with-chronology
(with-chronology f c)
Return a copy of a formatter that uses the given Chronology.
with-default-year
(with-default-year f default-year)
Return a copy of a formatter that uses the given default year.
with-locale
(with-locale f l)
Return a copy of a formatter that uses the given Locale.
with-pivot-year
(with-pivot-year f pivot-year)
Return a copy of a formatter that uses the given pivot year.
with-zone
(with-zone f dtz)
Return a copy of a formatter that uses the given DateTimeZone.