Next: , Previous: User Identification, Up: System Interface


40.5 Time of Day

This section explains how to determine the current time and the time zone.

— Function: current-time-string &optional time-value

This function returns the current time and date as a human-readable string. The format of the string is unvarying; the number of characters used for each part is always the same, so you can reliably use substring to extract pieces of it. It is wise to count the characters from the beginning of the string rather than from the end, as additional information may some day be added at the end.

The argument time-value, if given, specifies a time to format instead of the current time. The argument should be a list whose first two elements are integers. Thus, you can use times obtained from current-time (see below) and from file-attributes (see File Attributes).

          (current-time-string)
               => "Wed Oct 14 22:21:05 1987"
     
— Function: current-time

This function returns the system's time value as a list of three integers: (high low microsec). The integers high and low combine to give the number of seconds since 0:00 January 1, 1970 (local time), which is high * 2**16 + low.

The third element, microsec, gives the microseconds since the start of the current second (or 0 for systems that return time with the resolution of only one second).

The first two elements can be compared with file time values such as you get with the function file-attributes. See File Attributes.

— Function: current-time-zone &optional time-value

This function returns a list describing the time zone that the user is in.

The value has the form (offset name). Here offset is an integer giving the number of seconds ahead of UTC (east of Greenwich). A negative value means west of Greenwich. The second element, name, is a string giving the name of the time zone. Both elements change when daylight savings time begins or ends; if the user has specified a time zone that does not use a seasonal time adjustment, then the value is constant through time.

If the operating system doesn't supply all the information necessary to compute the value, both elements of the list are nil.

The argument time-value, if given, specifies a time to analyze instead of the current time. The argument should be a cons cell containing two integers, or a list whose first two elements are integers. Thus, you can use times obtained from current-time (see above) and from file-attributes (see File Attributes).

— Function: float-time &optional time-value

This function returns the current time as a floating-point number of seconds since the epoch. The argument time-value, if given, specifies a time to convert instead of the current time. The argument should have the same form as for current-time-string (see above), and it also accepts the output of current-time and file-attributes.

Warning: Since the result is floating point, it may not be exact. Do not use this function if precise time stamps are required.