Liking cljdoc? Tell your friends :D

clj-time.core

The core namespace for date-time operations in the clj-time library.

Create a DateTime instance with date-time (or a LocalDateTime instance with local-date-time), specifying the year, month, day, hour, minute, second, and millisecond:

=> (date-time 1986 10 14 4 3 27 456) #<DateTime 1986-10-14T04:03:27.456Z>

=> (local-date-time 1986 10 14 4 3 27 456) #<LocalDateTime 1986-10-14T04:03:27.456>

Less-significant fields can be omitted:

=> (date-time 1986 10 14) #<DateTime 1986-10-14T00:00:00.000Z>

=> (local-date-time 1986 10 14) #<LocalDateTime 1986-10-14T00:00:00.000>

Get the current time with (now) and the start of the Unix epoch with (epoch).

Once you have a date-time, use accessors like hour and second to access the corresponding fields:

=> (hour (date-time 1986 10 14 22)) 22

=> (hour (local-date-time 1986 10 14 22)) 22

The date-time constructor always returns times in the UTC time zone. If you want a time with the specified fields in a different time zone, use from-time-zone:

=> (from-time-zone (date-time 1986 10 22) (time-zone-for-offset -2)) #<DateTime 1986-10-22T00:00:00.000-02:00>

If on the other hand you want a given absolute instant in time in a different time zone, use to-time-zone:

=> (to-time-zone (date-time 1986 10 22) (time-zone-for-offset -2)) #<DateTime 1986-10-21T22:00:00.000-02:00>

In addition to time-zone-for-offset, you can use the time-zone-for-id and default-time-zone functions and the utc Var to constgruct or get DateTimeZone instances.

The functions after? and before? determine the relative position of two DateTime instances:

=> (after? (date-time 1986 10) (date-time 1986 9)) true

=> (after? (local-date-time 1986 10) (local-date-time 1986 9)) true

Often you will want to find a date some amount of time from a given date. For example, to find the time 1 month and 3 weeks from a given date-time:

=> (plus (date-time 1986 10 14) (months 1) (weeks 3)) #<DateTime 1986-12-05T00:00:00.000Z>

=> (plus (local-date-time 1986 10 14) (months 1) (weeks 3)) #<LocalDateTime 1986-12-05T00:00:00.000Z>

An Interval is used to represent the span of time between two DateTime instances. Construct one using interval, then query them using within?, overlaps?, and abuts?

=> (within? (interval (date-time 1986) (date-time 1990)) (date-time 1987)) true

To find the amount of time encompased by an interval, use in-seconds and in-minutes:

=> (in-minutes (interval (date-time 1986 10 2) (date-time 1986 10 14))) 17280

Note that all functions in this namespace work with Joda objects or ints. If you need to print or parse date-times, see clj-time.format. If you need to ceorce date-times to or from other types, see clj-time.coerce.

The core namespace for date-time operations in the clj-time library.

Create a DateTime instance with date-time (or a LocalDateTime instance with local-date-time),
specifying the year, month, day, hour, minute, second, and millisecond:

  => (date-time 1986 10 14 4 3 27 456)
  #<DateTime 1986-10-14T04:03:27.456Z>

  => (local-date-time 1986 10 14 4 3 27 456)
  #<LocalDateTime 1986-10-14T04:03:27.456>

Less-significant fields can be omitted:

  => (date-time 1986 10 14)
  #<DateTime 1986-10-14T00:00:00.000Z>

  => (local-date-time 1986 10 14)
  #<LocalDateTime 1986-10-14T00:00:00.000>

Get the current time with (now) and the start of the Unix epoch with (epoch).

Once you have a date-time, use accessors like hour and second to access the
corresponding fields:

  => (hour (date-time 1986 10 14 22))
  22

  => (hour (local-date-time 1986 10 14 22))
  22

The date-time constructor always returns times in the UTC time zone. If you
want a time with the specified fields in a different time zone, use
from-time-zone:

  => (from-time-zone (date-time 1986 10 22) (time-zone-for-offset -2))
  #<DateTime 1986-10-22T00:00:00.000-02:00>

If on the other hand you want a given absolute instant in time in a
different time zone, use to-time-zone:

  => (to-time-zone (date-time 1986 10 22) (time-zone-for-offset -2))
  #<DateTime 1986-10-21T22:00:00.000-02:00>

In addition to time-zone-for-offset, you can use the time-zone-for-id and
default-time-zone functions and the utc Var to constgruct or get DateTimeZone
instances.

The functions after? and before? determine the relative position of two
DateTime instances:

  => (after? (date-time 1986 10) (date-time 1986 9))
  true

  => (after? (local-date-time 1986 10) (local-date-time 1986 9))
  true

Often you will want to find a date some amount of time from a given date. For
example, to find the time 1 month and 3 weeks from a given date-time:

  => (plus (date-time 1986 10 14) (months 1) (weeks 3))
  #<DateTime 1986-12-05T00:00:00.000Z>

  => (plus (local-date-time 1986 10 14) (months 1) (weeks 3))
  #<LocalDateTime 1986-12-05T00:00:00.000Z>

An Interval is used to represent the span of time between two DateTime
instances. Construct one using interval, then query them using within?,
overlaps?, and abuts?

  => (within? (interval (date-time 1986) (date-time 1990))
              (date-time 1987))
  true

To find the amount of time encompased by an interval, use in-seconds and
in-minutes:

  => (in-minutes (interval (date-time 1986 10 2) (date-time 1986 10 14)))
  17280

Note that all functions in this namespace work with Joda objects or ints. If
you need to print or parse date-times, see clj-time.format. If you need to
ceorce date-times to or from other types, see clj-time.coerce.
raw docstring

abuts?clj

(abuts? i-a i-b)

Returns true if Interval i-a abuts i-b, i.e. then end of i-a is exactly the beginning of i-b.

Returns true if Interval i-a abuts i-b, i.e. then end of i-a is exactly the
beginning of i-b.
sourceraw docstring

agoclj

(ago period)

Returns a DateTime a supplied period before the present. e.g. (-> 5 years ago)

Returns a DateTime a supplied period before the present.
e.g. (-> 5 years ago)
sourceraw docstring

date-midnightclj

(date-midnight year)
(date-midnight year month)
(date-midnight year month day)

Constructs and returns a new DateMidnight in UTC. Specify the year, month of year, day of month. Note that month and day are 1-indexed. Any number of least-significant components can be ommited, in which case they will default to 1.

Constructs and returns a new DateMidnight in UTC.
Specify the year, month of year, day of month. Note that month and day are
1-indexed. Any number of least-significant components can be ommited, in which case
they will default to 1.
sourceraw docstring

date-timeclj

(date-time year)
(date-time year month)
(date-time year month day)
(date-time year month day hour)
(date-time year month day hour minute)
(date-time year month day hour minute second)
(date-time year month day hour minute second millis)

Constructs and returns a new DateTime in UTC. Specify the year, month of year, day of month, hour of day, minute if hour, second of minute, and millisecond of second. Note that month and day are 1-indexed while hour, second, minute, and millis are 0-indexed. Any number of least-significant components can be ommited, in which case they will default to 1 or 0 as appropriate.

Constructs and returns a new DateTime in UTC.
Specify the year, month of year, day of month, hour of day, minute if hour,
second of minute, and millisecond of second. Note that month and day are
1-indexed while hour, second, minute, and millis are 0-indexed.
Any number of least-significant components can be ommited, in which case
they will default to 1 or 0 as appropriate.
sourceraw docstring

DateTimeProtocolcljprotocol

Interface for various date time functions

Interface for various date time functions

minuteclj

(minute this)

Return the minute of hour component of the given date/time.

Return the minute of hour component of the given date/time.

after?clj

(after? this that)

Returns true if ReadableDateTime 'this' is strictly after date/time 'that'.

Returns true if ReadableDateTime 'this' is strictly after date/time 'that'.

hourclj

(hour this)

Return the hour of day component of the given date/time. A time of 12:01am will have an hour component of 0.

Return the hour of day component of the given date/time. A time of 12:01am will have an hour component of 0.

dayclj

(day this)

Return the day of month component of the given date/time.

Return the day of month component of the given date/time.

secondclj

(second this)

Return the second of minute component of the given date/time.

Return the second of minute component of the given date/time.

plus-clj

(plus- this period)

Returns a new date/time corresponding to the given date/time moved forwards by the given Period(s).

Returns a new date/time corresponding to the given date/time moved forwards by the given Period(s).

day-of-weekclj

(day-of-week this)

Return the day of week component of the given date/time. Monday is 1 and Sunday is 7

Return the day of week component of the given date/time. Monday is 1 and Sunday is 7

monthclj

(month this)

Return the month component of the given date/time.

Return the month component of the given date/time.

before?clj

(before? this that)

Returns true if ReadableDateTime 'this' is strictly before date/time 'that'.

Returns true if ReadableDateTime 'this' is strictly before date/time 'that'.

yearclj

(year this)

Return the year component of the given date/time.

Return the year component of the given date/time.

minus-clj

(minus- this period)

Returns a new date/time corresponding to the given date/time moved backwards by the given Period(s).

Returns a new date/time corresponding to the given date/time moved backwards by the given Period(s).

secclj

(sec this)

Return the second of minute component of the given date/time.

Return the second of minute component of the given date/time.

milliclj

(milli this)

Return the millisecond of second component of the given date/time.

Return the millisecond of second component of the given date/time.
sourceraw docstring

daysclj

(days)
(days n)

Given a number, returns a Period representing that many days. Without an argument, returns a PeriodType representing only days.

Given a number, returns a Period representing that many days.
Without an argument, returns a PeriodType representing only days.
sourceraw docstring

days?clj

(days? val)

Returns true if the given value is an instance of Days

Returns true if the given value is an instance of Days
sourceraw docstring

default-time-zoneclj

(default-time-zone)

Returns the default DateTimeZone for the current environment.

Returns the default DateTimeZone for the current environment.
sourceraw docstring

deprecatedclj

(deprecated message)
source

do-atcljmacro

(do-at base-date-time & body)

Like clojure.core/do except evalautes the expression at the given date-time

Like clojure.core/do except evalautes the expression at the given date-time
sourceraw docstring

do-at*clj

(do-at* base-date-time body-fn)
source

endclj

(end in)

Returns the end DateTime of an Interval.

Returns the end DateTime of an Interval.
sourceraw docstring

epochclj

(epoch)

Returns a DateTime for the begining of the Unix epoch in the UTC time zone.

Returns a DateTime for the begining of the Unix epoch in the UTC time zone.
sourceraw docstring

extendclj

(extend in & by)

Returns an Interval with an end ReadableDateTime the specified Period after the end of the given Interval

Returns an Interval with an end ReadableDateTime the specified Period after the end
of the given Interval
sourceraw docstring

first-day-of-the-monthclj

(first-day-of-the-month dt)
(first-day-of-the-month year month)
source

from-nowclj

(from-now period)

Returns a DateTime a supplied period after the present. e.g. (-> 30 minutes from-now)

Returns a DateTime a supplied period after the present.
e.g. (-> 30 minutes from-now)
sourceraw docstring

from-time-zoneclj

(from-time-zone dt tz)

Returns a new ReadableDateTime corresponding to the same point in calendar time as the given ReadableDateTime, but for a correspondingly different absolute instant in time.

Returns a new ReadableDateTime corresponding to the same point in calendar time as
the given ReadableDateTime, but for a correspondingly different absolute instant in
time.
sourceraw docstring

hoursclj

(hours)
(hours n)

Given a number, returns a Period representing that many hours. Without an argument, returns a PeriodType representing only hours.

Given a number, returns a Period representing that many hours.
Without an argument, returns a PeriodType representing only hours.
sourceraw docstring

hours?clj

(hours? val)

Returns true if the given value is an instance of Hours

Returns true if the given value is an instance of Hours
sourceraw docstring

in-daysclj

(in-days in)

Returns the number of standard days in the given Interval.

Returns the number of standard days in the given Interval.
sourceraw docstring

in-hoursclj

(in-hours in)

Returns the number of standard hours in the given Interval.

Returns the number of standard hours in the given Interval.
sourceraw docstring

in-millisclj

(in-millis in)

Returns the number of milliseconds in the given Interval.

Returns the number of milliseconds in the given Interval.
sourceraw docstring

in-minutesclj

(in-minutes in)

Returns the number of standard minutes in the given Interval.

Returns the number of standard minutes in the given Interval.
sourceraw docstring

in-monthsclj

(in-months in)

Returns the number of standard months in the given Interval.

Returns the number of standard months in the given Interval.
sourceraw docstring

in-msecsclj

(in-msecs in)

DEPRECATED: Returns the number of milliseconds in the given Interval.

DEPRECATED: Returns the number of milliseconds in the given Interval.
sourceraw docstring

in-secondsclj

(in-seconds in)

Returns the number of standard seconds in the given Interval.

Returns the number of standard seconds in the given Interval.
sourceraw docstring

in-secsclj

(in-secs in)

DEPRECATED: Returns the number of standard seconds in the given Interval.

DEPRECATED: Returns the number of standard seconds in the given Interval.
sourceraw docstring

in-weeksclj

(in-weeks in)

Returns the number of standard weeks in the given Interval.

Returns the number of standard weeks in the given Interval.
sourceraw docstring

in-yearsclj

(in-years in)

Returns the number of standard years in the given Interval.

Returns the number of standard years in the given Interval.
sourceraw docstring

intervalclj

(interval dt-a dt-b)

Returns an interval representing the span between the two given ReadableDateTimes. Note that intervals are closed on the left and open on the right.

Returns an interval representing the span between the two given ReadableDateTimes.
Note that intervals are closed on the left and open on the right.
sourceraw docstring

last-day-of-the-monthclj

(last-day-of-the-month dt)
(last-day-of-the-month year month)
source

local-dateclj

(local-date year month day)

Constructs and returns a new LocalDate. Specify the year, month, and day. Does not deal with timezones.

Constructs and returns a new LocalDate.
Specify the year, month, and day. Does not deal with timezones.
sourceraw docstring

local-date-timeclj

(local-date-time year)
(local-date-time year month)
(local-date-time year month day)
(local-date-time year month day hour)
(local-date-time year month day hour minute)
(local-date-time year month day hour minute second)
(local-date-time year month day hour minute second millis)

Constructs and returns a new LocalDateTime. Specify the year, month of year, day of month, hour of day, minute if hour, second of minute, and millisecond of second. Note that month and day are 1-indexed while hour, second, minute, and millis are 0-indexed. Any number of least-significant components can be ommited, in which case they will default to 1 or 0 as appropriate.

Constructs and returns a new LocalDateTime.
Specify the year, month of year, day of month, hour of day, minute if hour,
second of minute, and millisecond of second. Note that month and day are
1-indexed while hour, second, minute, and millis are 0-indexed.
Any number of least-significant components can be ommited, in which case
they will default to 1 or 0 as appropriate.
sourceraw docstring

millisclj

(millis)
(millis n)

Given a number, returns a Period representing that many milliseconds. Without an argument, returns a PeriodType representing only milliseconds.

Given a number, returns a Period representing that many milliseconds.
Without an argument, returns a PeriodType representing only milliseconds.
sourceraw docstring

mins-agoclj

(mins-ago d)
source

minusclj

(minus dt p)
(minus dt p & ps)

Returns a new date/time object corresponding to the given date/time moved backwards by the given Period(s).

Returns a new date/time object corresponding to the given date/time moved backwards by
the given Period(s).
sourceraw docstring

minutesclj

(minutes)
(minutes n)

Given a number, returns a Period representing that many minutes. Without an argument, returns a PeriodType representing only minutes.

Given a number, returns a Period representing that many minutes.
Without an argument, returns a PeriodType representing only minutes.
sourceraw docstring

minutes?clj

(minutes? val)

Returns true if the given value is an instance of Minutes

Returns true if the given value is an instance of Minutes
sourceraw docstring

monthsclj

(months)
(months n)

Given a number, returns a Period representing that many months. Without an argument, returns a PeriodType representing only months.

Given a number, returns a Period representing that many months.
Without an argument, returns a PeriodType representing only months.
sourceraw docstring

months?clj

(months? val)

Returns true if the given value is an instance of Months

Returns true if the given value is an instance of Months
sourceraw docstring

nowclj

(now)

Returns a DateTime for the current instant in the UTC time zone.

Returns a DateTime for the current instant in the UTC time zone.
sourceraw docstring

number-of-days-in-the-monthclj

(number-of-days-in-the-month dt)
(number-of-days-in-the-month year month)
source

overlaps?clj

(overlaps? i-a i-b)
(overlaps? start-a end-a start-b end-b)

With 2 arguments: Returns true of the two given Intervals overlap. Note that intervals that satisfy abuts? do not satisfy overlaps? With 4 arguments: Returns true if the range specified by start-a and end-a overlaps with the range specified by start-b and end-b.

With 2 arguments: Returns true of the two given Intervals overlap.
Note that intervals that satisfy abuts? do not satisfy overlaps?
With 4 arguments: Returns true if the range specified by start-a and end-a
overlaps with the range specified by start-b and end-b.
sourceraw docstring

plusclj

(plus dt p)
(plus dt p & ps)

Returns a new date/time corresponding to the given date/time moved forwards by the given Period(s).

Returns a new date/time corresponding to the given date/time moved forwards by
the given Period(s).
sourceraw docstring

secondsclj

(seconds)
(seconds n)

Given a number, returns a Period representing that many seconds. Without an argument, returns a PeriodType representing only seconds.

Given a number, returns a Period representing that many seconds.
Without an argument, returns a PeriodType representing only seconds.
sourceraw docstring

seconds?clj

(seconds? val)

Returns true if the given value is an instance of Seconds

Returns true if the given value is an instance of Seconds
sourceraw docstring

secsclj

(secs)
(secs n)

DEPRECATED

DEPRECATED
sourceraw docstring

secs?clj

(secs? val)

DEPRECATED

DEPRECATED
sourceraw docstring

startclj

(start in)

Returns the start DateTime of an Interval.

Returns the start DateTime of an Interval.
sourceraw docstring

time-zone-for-idclj

(time-zone-for-id id)

Returns a DateTimeZone for the given ID, which must be in long form, e.g. 'America/Matamoros'.

Returns a DateTimeZone for the given ID, which must be in long form, e.g.
'America/Matamoros'.
sourceraw docstring

time-zone-for-offsetclj

(time-zone-for-offset hours)
(time-zone-for-offset hours minutes)

Returns a DateTimeZone for the given offset, specified either in hours or hours and minutes.

Returns a DateTimeZone for the given offset, specified either in hours or
hours and minutes.
sourceraw docstring

to-time-zoneclj

(to-time-zone dt tz)

Returns a new ReadableDateTime corresponding to the same absolute instant in time as the given ReadableDateTime, but with calendar fields corresponding to the given TimeZone.

Returns a new ReadableDateTime corresponding to the same absolute instant in time as
the given ReadableDateTime, but with calendar fields corresponding to the given
TimeZone.
sourceraw docstring

todayclj

(today)

Constructs and returns a new LocalDate representing today's date. LocalDate objects do not deal with timezones at all.

Constructs and returns a new LocalDate representing today's date.
LocalDate objects do not deal with timezones at all.
sourceraw docstring

today-atclj

(today-at hours minutes)
(today-at hours minutes seconds)
(today-at hours minutes seconds millis)
source

today-at-midnightclj

(today-at-midnight)

Returns a DateMidnight for today at midnight in the UTC time zone.

Returns a DateMidnight for today at midnight in the UTC time zone.
sourceraw docstring

utcclj

DateTimeZone for UTC.

DateTimeZone for UTC.
sourceraw docstring

weeksclj

(weeks)
(weeks n)

Given a number, returns a Period representing that many weeks. Without an argument, returns a PeriodType representing only weeks.

Given a number, returns a Period representing that many weeks.
Without an argument, returns a PeriodType representing only weeks.
sourceraw docstring

weeks?clj

(weeks? val)

Returns true if the given value is an instance of Weeks

Returns true if the given value is an instance of Weeks
sourceraw docstring

within?clj

(within? i dt)
(within? start end test)

With 2 arguments: Returns true if the given Interval contains the given ReadableDateTime. Note that if the ReadableDateTime is exactly equal to the end of the interval, this function returns false. With 3 arguments: Returns true if the start ReadablePartial is equal to or before and the end ReadablePartial is equal to or after the test ReadablePartial.

With 2 arguments: Returns true if the given Interval contains the given
ReadableDateTime. Note that if the ReadableDateTime is exactly equal to the
end of the interval, this function returns false.
With 3 arguments: Returns true if the start ReadablePartial is
equal to or before and the end ReadablePartial is equal to or after the test
ReadablePartial.
sourceraw docstring

year-monthclj

(year-month year)
(year-month year month)

Constructs and returns a new YearMonth. Specify the year and month of year. Month is 1-indexed and defaults to January (1).

Constructs and returns a new YearMonth.
Specify the year and month of year. Month is 1-indexed and defaults
to January (1).
sourceraw docstring

yearsclj

(years)
(years n)

Given a number, returns a Period representing that many years. Without an argument, returns a PeriodType representing only years.

Given a number, returns a Period representing that many years.
Without an argument, returns a PeriodType representing only years.
sourceraw docstring

years?clj

(years? val)

Returns true if the given value is an instance of Years

Returns true if the given value is an instance of Years
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close