S-Lang Run-Time Library Reference: Version 2.0.4: Time and Date Functions

Next Previous Contents

## 11. Time and Date Functions

## 11.1 ctime

Synopsis

  Convert a calendar time to a string

Usage

  `String_Type ctime(Long_Type secs)`

Description

  This function returns a string representation of the time as given by `secs` seconds since 00:00:00 UTC, Jan 1, 1970.

See Also

  `time, _time, localtime, gmtime`

## 11.2 gmtime

Synopsis

  Break down a time in seconds to the GMT timezone

Usage

  `Struct_Type gmtime (Long_Type secs)`

Description

  The `gmtime` function is exactly like `localtime` except that the values in the structure it returns are with respect to GMT instead of the local timezone. See the documentation for `localtime` for more information.

Notes

  On systems that do not support the `gmtime` C library function, this function is the same as `localtime`.

See Also

  `localtime, _time, mktime`

## 11.3 localtime

Synopsis

  Break down a time in seconds to the local timezone

Usage

  `Struct_Type localtime (Long_Type secs)`

Description

  The `localtime` function takes a parameter `secs` representing the number of seconds since 00:00:00, January 1 1970 UTC and returns a structure containing information about `secs` in the local timezone. The structure contains the following `Int_Type` fields:

  `tm_sec` The number of seconds after the minute, normally in the range 0 to 59, but can be up to 61 to allow for leap seconds.

  `tm_min` The number of minutes after the hour, in the range 0 to 59.

  `tm_hour` The number of hours past midnight, in the range 0 to 23.

  `tm_mday` The day of the month, in the range 1 to 31.

  `tm_mon` The number of months since January, in the range 0 to 11.

  `tm_year` The number of years since 1900.

  `tm_wday` The number of days since Sunday, in the range 0 to 6.

  `tm_yday` The number of days since January 1, in the range 0 to 365.

  `tm_isdst` A flag that indicates whether daylight saving time is in effect at the time described. The value is positive if daylight saving time is in effect, zero if it is not, and negative if the information is not available.

See Also

  `gmtime, _time, ctime, mktime`

## 11.4 mktime

Synopsis

  Convert a time-structure to seconds

Usage

  `secs = mktime (Struct_Type tm)`

Description

  The `mktime` function is essentially the inverse of the `localtime` function. See the documentation for that function for more details.

See Also

  `localtime, gmtime, _time`

## 11.5 _tic

Synopsis

  Reset the CPU timer

Usage

  `_tic ()`

Description

  The `_tic` function resets the internal CPU timer. The `_toc` may be used to read this timer. See the documentation for the `_toc` function for more information.

Example
See Also

  `_toc, times, tic, toc`

## 11.6 tic

Synopsis

  Reset the interval timer

Usage

  `void tic ()`

Description

  The `tic` function resets the internal interval timer. The `toc` may be used to read the interval timer.

Example

  The tic/toc functions may be used to measure execution times. For example, at the slsh prompt, they may be used to measure the speed of a loop:

  > `

  >        slsh> tic; loop (500000); toc;
  >        0.06558

  > `

Notes

  On Unix, this timer makes use of the C library `gettimeofday` function.

See Also

  `toc, times`

## 11.7 _time

Synopsis

  Get the current calendar time in seconds

Usage

  `Long_Type _time ()`

Description

  The `_time` function returns the number of elapsed seconds since 00:00:00 UTC, January 1, 1970. A number of functions (`ctime`, `gmtime`, `localtime`, etc.) are able to convert such a value to other representations.

See Also

  `ctime, time, localtime, gmtime`

## 11.8 time

Synopsis

  Return the current date and time as a string

Usage

  `String_Type time ()`

Description

  This function returns the current time as a string of the form:

  > `

  >         Sun Apr 21 13:34:17 1996

  > `

See Also

  `ctime, message, substr`

## 11.9 times

Synopsis

  Get process times

Usage

  `Struct_Type times ()`

Description

  The `times` function returns a structure containing the following fields:

  > `

  >         tms_utime     (user time)
  >         tms_stime     (system time)
  >         tms_cutime    (user time of child processes)
  >         tms_cstime    (system time of child processes)

  > `

Notes

  Not all systems support this function.

See Also

  `_tic, _toc, _time`

## 11.10 _toc

Synopsis

  Get the elapsed CPU time for the current process

Usage

  `Double_Type _toc ()`

Description

  The `_toc` function returns the elapsed CPU time in seconds since the last call to `_tic`. The CPU time is the amount of time the CPU spent running the code of the current process.

Example
Notes

  This function may not be available on all systems.

  The implementation of this function is based upon the `times` system call. The precision of the clock is system dependent and may not be very accurate for small time intervals. For this reason, the tic/toc functions may be more useful for small time-intervals.

See Also

  `_tic, _tic, _toc, times, _time`

## 11.11 toc

Synopsis

  Read the interval timer

Usage

  `Double_Type toc ()`

Description

  The `toc` function returns the elapsed time in seconds since the last call to `tic`. See the documentation for the `tic` function for more information.

See Also

  `tic, _tic, _toc, times, _time`

Next Previous Contents