如何在Fortran中以毫秒为单位获取当前时间?

Sam*_*oor -2 time fortran

我希望在Fortran中获得当前系统时间(以毫秒为单位).我无法使用system_clock,因为我无法弄清楚如何从中获取当前时间.

Ale*_*ogt 7

这说明了如何使用以下方法获取自午夜以来的时间(以毫秒为单位)date_and_time:

program time
  integer :: values(8)
  real    :: rTime

  ! Get the values
  call date_and_time(values=values)

  ! From https://gcc.gnu.org/onlinedocs/gfortran/DATE_005fAND_005fTIME.html
  ! values(5) ... The hour of the day
  ! values(6) ... The minutes of the hour
  ! values(7) ... The seconds of the minute
  ! values(8) ... The milliseconds of the second 

  ! Calculate time since midnight
  rTime = ( values(5) )*60.         ! Hours to minutes
  rTime = ( rTime + values(6) )*60. ! Minutes to seconds
  rTime = ( rTime + values(7) )*1e3 ! Seconds to milliseconds
  rTime = rTime + values(8)         ! Add milliseconds

  ! Time in seconds 
  print *, 'Time (ms) since midnight', rTime
end program
Run Code Online (Sandbox Code Playgroud)