program DateToUnixTimestamp implicit none integer :: year, month, day, hour, minute, second integer(8) :: unix_timestamp integer(8) :: days_since_epoch, seconds_since_midnight integer, parameter :: epoch_start = 719163 ! Julian day number for 1970-01-01 ! Example date and time year = 2024 month = 8 day = 28 hour = 12 minute = 34 second = 56 ! Calculate the number of days since the Unix epoch days_since_epoch = julday(year, month, day) - epoch_start ! Calculate the number of seconds since midnight seconds_since_midnight = hour * 3600 + minute * 60 + second ! Calculate the Unix timestamp unix_timestamp = days_since_epoch * 86400 + seconds_since_midnight print *, "Unix Timestamp: ", unix_timestamp end program DateToUnixTimestamp ! Function to calculate Julian day number for a given Gregorian date integer function julday(year, month, day) implicit none integer, intent(in) :: year, month, day integer :: a, y, m a = (14 - month) / 12 y = year + 4800 - a m = month + 12 * a - 3 julday = day + ((153 * m + 2) / 5) + 365 * y + (y / 4) - (y / 100) + (y / 400) - 32045 end function julday
julday
DATE_AND_TIME()
CALL DATE_AND_TIME(date=dt)
dt
JULIAN_DATE()
CALL JULIAN_DATE(2024, 8, 28, jd)
GREGORIAN_DATE()
CALL GREGORIAN_DATE(jd, year, month, day)
jd = 2460150
TIME()
CALL TIME(time_string)
CPU_TIME()
CALL CPU_TIME(cpu_time)
cpu_time
DATE()
CALL DATE(date_string)