Fortran Library Reference

time, ctime, ltime, gmtime: Get System Time

These routines have the following functions:

time

 Standard version: Get system time as integer (seconds since 0 GMT 1/1/70)VMS Version: Get the system time as character (hh:mm:ss)

ctime

Convert a system time to an ASCII string. 

ltime

Dissect a system time into month, day, and so forth, local time. 

gmtime

Dissect a system time into month, day, and so forth, GMT.  

time: Get System Time

For time(), there are two versions, a standard version and a VMS version. If you use the f77 command-line option -lV77, then you get the VMS version for time() and for idate(); otherwise, you get the standard versions.

The standard function is called by:

INTEGER*4 time or INTEGER*8

n = time() Standard Version

Return value 

INTEGER*4

 Output

Time, in seconds, since 0:0:0, GMT, 1/1/70 

INTEGER*8 OutputIn 64-bit environments, time returns an INTEGER*8 value

The function time() returns an integer with the time since 00:00:00 GMT, January 1, 1970, measured in seconds. This is the value of the operating system clock.

Example: time(), version standard with the operating system:


    INTEGER*4  n, time
    n = time()
    write(*,*) 'Seconds since 0 1/1/70 GMT = ', n
    end
demo% f77 -silent ttime.f
demo% a.out 
 Seconds since 0 1/1/70 GMT =   913240205
demo% 

The VMS version of time is a subroutine that gets the current system time as a character string.

The VMS subroutine is called by:

call time( t ) VMS Version

t

character*8

Output 

Time, in the form hh:mm:ss hh, mm, and ss are each two digits: hh is the hour; mm is the minute; ss is the second

Example: time(t), VMS version, ctime--convert the system time to ASCII:


    character  t*8
    call time( t )
    write(*, "(' The current time is ', A8 )")  t
    end
demo% f77 -silent ttimeV.f -lV77 
demo% a.out 
 The current time is 08:14:13 
demo% 

ctime: Convert System Time to Character

The function ctime converts a system time, stime, and returns it as a 24-character ASCII string.

The function is called by:

CHARACTER ctime*24

string = ctime( stime )

stime

INTEGER*4

Input 

System time from time() (standard version)

Return value 

character*24

Output 

System time as character string. Declare ctime and string as character*24.

The format of the ctime returned value is shown in the following example. It is described in the man page ctime(3C).

Example: ctime():


    character*24 ctime, string
    INTEGER*4  n, time
    n = time()
    string = ctime( n )
    write(*,*) 'ctime: ', string
    end
demo% f77 -silent tctime.f 
demo% a.out 
 ctime: Wed Dec  9 13:50:05 1998 
demo% 

ltime: Split System Time to Month, Day,... (Local)

This routine dissects a system time into month, day, and so forth, for the local time zone.

The subroutine is called by:

call ltime( stime, tarray )

stime

INTEGER*4

Input 

System time from time() (standard version)

tarray

INTEGER*4(9)

Output 

System time, local, as day, month, year, ...  

For the meaning of the elements in tarray, see the next section.

Example: ltime():


    integer*4  stime, tarray(9), time
    stime = time()
    call ltime( stime, tarray )
    write(*,*) 'ltime: ', tarray
    end
demo% f77 -silent tltime.f 
demo% a.out 
 ltime: 25 49 10 12 7 91 1 223 1 
demo% 

gmtime: Split System Time to Month, Day, ... (GMT)

This routine dissects a system time into month, day, and so on, for GMT.

The subroutine is:

call gmtime( stime, tarray )

stime

INTEGER*4

Input 

System time from time() (standard version)

tarray

INTEGER*4(9)

Output 

System time, GMT, as day, month, year, ...  

Example: gmtime:


    integer*4  stime, tarray(9), time
    stime = time()
    call gmtime( stime, tarray )
    write(*,*) 'gmtime: ', tarray
    end
demo% f77 -silent tgmtime.f 
demo% a.out 
 gmtime:   12  44  19  18  5  94  6  168  0 
demo% 

Here are the tarray() values for ltime and gmtime: index, units, and range:

Seconds (0 - 61) 

Minutes (0 - 59) 

Hours (0 - 23) 

Day of month (1 - 31) 

Months since January (0 - 11) 

Year - 1900 

Day of week (Sunday = 0) 

Day of year (0 - 365) 

Daylight Saving Time, 1 if DST in effect 

These values are defined by the C library routine ctime(3C), which explains why the system may return a count of seconds greater than 59. See also: idate(3F), and fdate(3F).

ctime64, gmtime64, ltime64: System Time Routines for 64-bit Environments

These are versions of the corresponding routines ctime, gmtime, and ltime, to provide portability on 64-bit environments. They are identical to these routines except that the input variable stime must be INTEGER*8.

When used in a 32-bit environment with an INTEGER*8 stime, if the value of stime is beyond the INTEGER*4 range ctime64 returns all asterisks, while gmtime and ltime fill the tarray array with -1.