Skip to content

Instantly share code, notes, and snippets.

@scivision
Created June 15, 2023 13:59
Show Gist options
  • Save scivision/c33833ee49bc4ce6f65555951d2735ec to your computer and use it in GitHub Desktop.
Save scivision/c33833ee49bc4ce6f65555951d2735ec to your computer and use it in GitHub Desktop.
Get local machine time zone in Fortran
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