知識社群Login
fortran 的 時間計算 基礎
by 高顯忠, 2010-12-03 09:27, Views(2321)
!dec$if(.false.)

底下是 online help , 關於 date_and_time() 的說明

DATE_AND_TIME
Intrinsic Subroutine: Returns character data on the real-time clock and date 
in a form compatible with the representations defined in Standard ISO 8601:1988. 

Syntax 

CALL DATE_AND_TIME ( [date] [, time] [, zone] [, values] )


date 
(Optional; output) Must be scalar and of type default character; its length must be at least 8 
to contain the complete value. Its leftmost 8 characters are set to a value of the form CCYYMMDD, where:

CC  Is the century  
YY  Is the year within the century  
MM  Is the month within the year  
DD  Is the day within the month 


time 
(Optional; output) Must be scalar and of type default character; its length must be 
at least 10 to contain the complete value. Its leftmost 10 characters are set to a value of the form hhmmss.sss, where:

hh  Is the hour of the day  
mm  Is the minutes of the hour 
ss.sss  Is the seconds and milliseconds of the minute  


zone 
(Optional; output) Must be scalar and of type default character; its length must be 
at least 5 to contain the complete value. Its leftmost 5 characters are set to a value 
of the form hhmm, where hh and mm are the time difference with respect to Coordinated 
Universal Time (UTC) in hours and parts of an hour expressed in minutes, respectively. 
UTC (also known as Greenwich Mean Time) is defined by CCIR Recommendation 460-2.

values 
(Optional; output) Must be of type default integer. One-dimensional array with size of 
at least 8. The values returned in values are as follows:

values (1)  The 4-digit year  
values (2)  The month of the year  
values (3)  The day of the month  
values (4)  The time difference with respect to Coordinated Universal Time (UTC) in minutes  
values (5)  The hour of the day (range 0 to 23) - local time  
values (6)  The minutes of the hour (range 0 to 59) - local time  
values (7)  The seconds of the minute (range 0 to 59) - local time  
values (8)  The milliseconds of the second (range 0 to 999) - local time  

Compatibility 

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB 

See Also: GETDAT, GETTIM, IDATE, FDATE, TIME, ITIME, RTC, CLOCK

Example 

Consider the following example executed on 2000 March 28 at 11:04:14.5:

  INTEGER DATE_TIME (8)
  CHARACTER (LEN = 12) REAL_CLOCK (3)

  CALL DATE_AND_TIME (REAL_CLOCK (1), REAL_CLOCK (2), &
                      REAL_CLOCK (3), DATE_TIME)

This assigns the value "20000328" to REAL_CLOCK (1), the value "110414.500" to REAL_CLOCK (2), and the value "-0500" to REAL_CLOCK (3). The following values are assigned to DATE_TIME: 2000, 3, 28, -300, 11, 4, 14, and 500.

The following shows another example:

CHARACTER(10) t
CHARACTER(5) z
CALL DATE_AND_TIME(TIME = t, ZONE = z)

!dec$endif
! ---------------------------------------------------------

program VF0904
implicit none
!
    INTEGER DATE_TIME(8), i, ms
    CHARACTER(LEN= 12) REAL_CLOCK(3)

    CALL DATE_AND_TIME (REAL_CLOCK (1), REAL_CLOCK (2), &
                        REAL_CLOCK (3), DATE_TIME)
    !
do i=1, 3
  print *, 'i, data= ', i, real_clock(i)
end do
pause

do i=1, 8
  print *, 'i, data= ', i, date_time(i)
end do
pause

ms= date_time(3) ! = day number
ms= mod(ms, 21) ! max.= 21- days

ms= ms*24 + date_time(5) ! --> hours
ms= ms*60 + date_time(6) ! --> min
ms= ms*60 + date_time(7) ! --> sec
ms= ms*1000 + date_time(8) ! --> ms

print *, 'ms= ', ms
pause
end program VF0904
! -----------------------------------------------------

!dec$if(.false.)


!dec$endif