Next Previous Contents

8. Time and Date Functions

8.1 _time

Synopsis

Get the current time in seconds

Usage

ULong_Type _time ()

Description

The _time function returns the number of elapsed seconds since 00:00:00 GMT, January 1, 1970. The ctime function may be used to convert this into a string representation.

See Also

ctime, time, localtime, gmtime

8.2 ctime

Synopsis

Convert a calendar time to a string

Usage

String_Type ctime(ULong_Type secs)

Description

This function returns a string representation of the time as given by secs seconds since 1970.

See Also

time, _time, localtime, gmtime

8.3 gmtime

Synopsis

Break down a time in seconds to 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

8.4 localtime

Synopsis

Break down a time in seconds to 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

8.5 tic

Synopsis

Start timing

Usage

void tic ()

Description

The tic function restarts the internal clock used for timing the execution of commands. To get the elapsed time of the clock, use the toc function.

See Also

toc, times

8.6 time

Synopsis

Return the current data 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

8.7 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, _times

8.8 toc

Synopsis

Get elapsed CPU time

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

The tic and toc functions are ideal for timing the execution of the interpreter:

     variable a = "hello", b = "world", c, n = 100000, t;
     
     tic ();  loop (n) c = a + b; t = toc ();
     vmessage ("a+b took %f seconds\n", t);
     tic ();  loop (n) c = strcat(a,b); t = toc ();
     vmessage ("strcat took %f seconds\n", t);
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.

See Also

tic, times, _time


Next Previous Contents