Created
June 15, 2023 13:59
-
-
Save scivision/c33833ee49bc4ce6f65555951d2735ec to your computer and use it in GitHub Desktop.
Get local machine time zone in Fortran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program main | |
!! prints local machine timezone offset from UTC in hours | |
!! based on https://github.com/wavebitscientific/datetime-fortran/pull/80/files | |
use, intrinsic :: iso_fortran_env, only: real64 | |
implicit none | |
character(len=5) :: zone | |
integer :: values(8) | |
integer :: hour, minute | |
real(real64), parameter :: m2h = 1 / 60._real64 | |
real(real64) :: machinetimezone | |
! Obtain local machine time zone information | |
call date_and_time(zone=zone, values=values) | |
read(zone(1:3), '(i3)') hour | |
read(zone(4:5), '(i2)') minute | |
if(hour<0)then | |
machinetimezone = hour - minute * m2h | |
else | |
machinetimezone = hour + minute * m2h | |
end if | |
print *, machinetimezone | |
end program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment