Date bug? For me, August changes to September
David Fletcher
dave at thefletchers.net
Sat Oct 12 21:57:55 UTC 2013
On Sat, 2013-10-12 at 20:35 +0200, Johnny Rosenberg wrote:
> Now:
> $ date -d @0 +'%F %T'
> 1970-01-01 01:00:00
> $
>
I find my curiosity aroused too. At the moment I'm working on a little
project to interpret gpx track files from my Garmin GPS. The lines in
the file that contain the time the track point was recorded are like
this:-
<time>2013-08-12T16:08:21Z</time>
Using code similar to that in a previous project,
PointTimeStruct.tm_year = atoi(GFTag.c_str() + 6) - 1900;
PointTimeStruct.tm_mon = atoi(GFTag.c_str() + 11);
PointTimeStruct.tm_mday = atoi(GFTag.c_str() + 14);
PointTimeStruct.tm_hour = atoi(GFTag.c_str() + 17);
PointTimeStruct.tm_min = atoi(GFTag.c_str() + 20);
PointTimeStruct.tm_sec = atoi(GFTag.c_str() + 23);
PointTimeStruct.tm_isdst = 0;
NextPt->SecondsSinceEpoch = mktime(&PointTimeStruct);
where GFTag is a string object loaded with the above gpx <time> line.
Debug output of the structure elements assigned above shows
Year 113
Month 8
Date 12
Hour 16
Minute 8
Second 21
so I'm picking out the correct data from the gpx file. I can't remember
the reason for subtracting 1900 from the year, but debug output showing
NextPt->SecondsSinceEpoch is
lat is 51.5798 degrees
lon is -1.82932 degrees
ele is 87.836 metres
Time is 1379002101 seconds
Now, if I put the time in seconds back into the date command that Johnny
R was using I get:-
dave at Tosh-NB520:~/code$ date -d @1379002101 +'%F %T'
2013-09-12 17:08:21
So, the hour has gone up by one, which I'm not too bothered about.
Everything else is correct EXCEPT that August has changed into
September! How the hell has that happened?
Thanks to all who have had the patience to read this.
Dave
More information about the ubuntu-users
mailing list