Getting the current date and time in Fortran |
|
To get the current date and time, declare two arrays of type
integer*4, each with three elements. Then call
the built-in idate and itime functions
to place the day, month, and year into the first array and the
hour, minute, and second into the second array:
program when
integer*4 today(3), now(3)
call idate(today) ! today(1)=day, (2)=month, (3)=year
call itime(now) ! now(1)=hour, (2)=minute, (3)=second
write ( *, 1000 ) today(2), today(1), today(3), now
1000 format ( 'Date ', i2.2, '/', i2.2, '/', i4.4, '; time ',
& i2.2, ':', i2.2, ':', i2.2 )
stop
end
Running this program might produce output something like this:Date 04/01/1995; time 14:07:40