Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

bogus results from gmtime

evankw21
Beginner
553 Views
I call gmtime to convert seconds since 1970 to the corresponding year, month, day, etc. It works under Windows, but when called under Linux, it gives incorrect results. For example, the year, which is supposed to be the year since 1900, is over 200,000. I tried calling it with seconds_since_1970 = 0, and it gave a set of seemingly random numbers, instead of the 1 Jan 1970 answer it should get. I'm surprised no one else is getting this error. Hard to imagine the code around it could be messing it up. I've seen some posts about multithreading issues, but this code is not multithreaded.

Any help would be appreciated. In the mean time, I guess I'll code my own algorithm...

Evan
0 Kudos
1 Reply
Ron_Green
Moderator
553 Views
It seems to work for me, with a question about the daylight savings time, which I would expect to be "1" and not "0". Make sure you have USE IFPORT and IMPLICIT NONE in your code, such as I have below:
[bash]program gmtim
use IFPORT
implicit none

integer(4) stime, timearray(9)

! initialize stime to number of seconds since
! 00:00:00 GMT January 1, 1970

stime = time()

CALL GMTIME (stime, timearray)

print *, "seconds ", timearray(1)
print*, "minutes ", timearray(2)
print*, "hours ", timearray(3)
print*, "day in month ", timearray(4)
print*, "month ", timearray(5)
print*, "years since 1900 ", timearray(6)
print*, "day of week ", timearray(7)
print*, "day of year ", timearray(8)
print*, "daylight savings?", timearray(9)

end program gmtim
[/bash]


and the results

$ date ; ./gmtim
Thu Apr 22 13:54:11 PDT 2010
seconds 11
minutes 54
hours 20
day in month 22
month 3
years since 1900 110
day of week 4
day of year 111
daylight savings? 0

Note that month is zero-based, months 0-11, so one could add 1 to this. I'm using PDT, GMT - 8 so I'd have to subract 8 from GMT returned AND the results give 0 for Daylight, add 1.

Other than that, works fine for me.

ron
0 Kudos
Reply