I'm post-processing loglines from a log written by syslog-ng - maybe not the best of interfaces, but the log is the best record of the activity I'm checking for. The loglines have a timestamp like this: 2006-08-15T20:33:57+0200 I need to convert that to a number of seconds since 1970-01-01 00:00:00 UTC. I looked at strptime, but that doesn't take the GMT-offset into account, so I decided to sscanf() the timestamp into a 'tm' structure. Then I use mktime to turn into a number seconds. The question is - mktime() looks at the local timezone settings ... which I'd rather it didn't. OK, I could fiddle with the TZ variable and make it UTC, but as I'm multi-threaded this could have undesired effects elsewhere. AFAICT, syslog-ng does not have an option for also logging the timestamp as the number of seconds since the epoch, which would obviously otherwise have been the best option. I might still look into patching syslog-ng. Any other suggestions? /Per Jessen, Zürich
Per Jessen wrote:
The question is - mktime() looks at the local timezone settings ... which I'd rather it didn't. OK, I could fiddle with the TZ variable and make it UTC, but as I'm multi-threaded this could have undesired effects elsewhere.
I should explain what I'm really doing here: I sscanf() the timestamp into a 'tm' struct, and I correct the year and month such that they comply with what 'tm' expects. Then I convert to a number of seconds since the epoch using mktime() and subtracting the number of seconds as specified in the offset part of the timestamp - e.g. +0200 becomes -7200 seconds. But my number of seconds always ends up being off by 3600 seconds, i.e. 3600 seconds less than it should be. /Per Jessen, Zürich
participants (1)
-
Per Jessen