This module provides computation of local and universal time, day of the week, and many time conversion functions.
Time is local when it is adjusted in accordance with the current time zone and daylight saving. Time is universal when it reflects the time at longitude zero, without any adjustment for daylight saving. Universal Coordinated Time (UTC) time is also called Greenwich Mean Time (GMT).
The time functions
All dates conform to the Gregorian calendar. This calendar was introduced by Pope Gregory XIII in 1582 and was used in all Catholic countries from this year. Protestant parts of Germany and the Netherlands adopted it in 1698, England followed in 1752, and Russia in 1918 (the October revolution of 1917 took place in November according to the Gregorian calendar).
The Gregorian calendar in this module is extended back to year 0. For a given date, the gregorian days is the number of days up to and including the date specified. Similarly, the gregorian seconds for a specified date and time is the number of seconds up to and including the specified date and time.
For computing differences between epochs in time, use
the functions counting gregorian days or seconds. If epochs are
specified as local time, they must be converted to universal time
to get the correct value of the elapsed time between epochs.
Use of function
Different definitions exist for the week of the year.
This module contains a week of the year implementation
conforming to the ISO 8601 standard. As the week number for a
specified date can fall on the previous, the current, or on the next
year, it is important to specify both the year and the week number.
Functions
Year cannot be abbreviated. For example, 93 denotes year 93, not 1993. The valid range depends on the underlying operating system. The date tuple must denote a valid date.
Computes the number of gregorian days starting with year 0 and ending at the specified date.
Computes the number of gregorian seconds starting with year 0 and ending at the specified date and time.
Computes the day of the week from the specified
Computes the date from the specified number of gregorian days.
Computes the date and time from the specified number of gregorian seconds.
Checks if the specified year is a leap year.
Returns tuple
Returns tuple
Computes the number of days in a month.
Returns the local time reported by the underlying operating system.
Converts from local time to Universal Coordinated Time (UTC).
This function is deprecated. Use
Converts from local time to Universal Coordinated Time (UTC).
The return value is a list of 0, 1, or 2 possible UTC times:
For a local
For a local
For all other local times only one corresponding UTC exists.
Returns Universal Coordinated Time (UTC)
converted from the return value from
Returns local date and time converted from the return value from
Returns Universal Coordinated Time (UTC)
converted from the return value from
Converts an RFC 3339 timestamp into system time. The data format
of RFC 3339 timestamps is described by
Valid option:
The time unit of the return value.
The default is
1> calendar:rfc3339_to_system_time("2018-02-01T16:17:58+01:00"). 1517498278 2> calendar:rfc3339_to_system_time("2018-02-01 15:18:02.088Z", [{unit, nanosecond}]). 1517498282088000000
Converts a specified number of seconds into days, hours, minutes,
and seconds.
Computes the time from the specified number of seconds.
Converts a specified system time into local date and time.
Converts a system time into an RFC 3339 timestamp. The data format
of RFC 3339 timestamps is described by
Valid options:
The offset, either a string or an integer, to be
included in the formatted string.
An empty string, which is the default, is interpreted
as local time. A non-empty string is included as is.
The time unit of the integer is the same as the one
of
The character used as time designator, that is,
the date and time separator. The default is
The time unit of
1> calendar:system_time_to_rfc3339(erlang:system_time(second)). "2018-04-23T14:56:28+02:00" 2> calendar:system_time_to_rfc3339(erlang:system_time(second), [{offset, "-02:00"}]). "2018-04-23T10:56:52-02:00" 3> calendar:system_time_to_rfc3339(erlang:system_time(second), [{offset, -7200}]). "2018-04-23T10:57:05-02:00" 4> calendar:system_time_to_rfc3339(erlang:system_time(millisecond), [{unit, millisecond}, {time_designator, $\s}, {offset, "Z"}]). "2018-04-23 12:57:20.482Z"
Converts a specified system time into universal date and time.
Returns the difference between two
This function is obsolete. Use the conversion functions for gregorian days and seconds instead.
Returns the number of seconds since midnight up to the specified time.
Returns the Universal Coordinated Time (UTC) reported by the underlying operating system. Returns local time if universal time is unavailable.
Converts from Universal Coordinated Time (UTC) to local time.
This function checks if a date is a valid.
The notion that every fourth year is a leap year is not completely true. By the Gregorian rule, a year Y is a leap year if one of the following rules is valid:
Y is divisible by 4, but not by 100.
Y is divisible by 400.
Hence, 1996 is a leap year, 1900 is not, but 2000 is.
Local time is obtained from the Erlang BIF
The following apply: