- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Any help would be appreciated. In the mean time, I guess I'll code my own algorithm...
Evan
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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
[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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page