The time() function works with and without an argument. Without an argument, this function returns the current system time. With a numeric argument, the time() function adds the argument (as seconds) to the date and time January 1, 1970 00:00:00 GMT and returns the new time and date based on the current time zone information.

The output type of the time() function can be controlled through type casting. By default, the function returns a string. If the function is converted to a numeric, the output is converted into an integer that represents the number of seconds since January 1, 1970 00:00:00 GMT.

For example:

x = string(time());
print(x);

The string() function returns the time in the following format:

DD-MONTH-YYYY HH:MM:SS

However, the following numeric function returns a number similar to 958159632.

x = numeric(time());
print(x);

Type conversions also work when a value is passed as an argument to the function.

The following script prints the date and time, waits five seconds, and prints the date and time again. It also converts a number read from the input file into a date and time.

ASL Script (time_do.asl):
START {
 y:integer eol
}
do {
 print(time());
 sleep(5);
 print(time());
 x = time(y);
 print(x);
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
Input (time_do.txt):
987517893
Output:
$ sm_adapter --file=time_do.txt time_do.asl
12-May-2000 03:28:47
12-May-2000 03:28:52
17-Apr-2001 10:31:33
$