C++ mktime and DST -
i processing stored dates , times. store them in file in gmt in string format (i.e. ddmmyyyyhhmmss
). when client queries, convert string struct tm
, convert seconds using mktime
. check invalid datetime. again convert seconds string format. these processing fine, no issues @ all.
but have 1 weird issue: stored date , time in gmt locale gmt. because of day light saving, locale time changed gmt+1. now, if query stored date , time 1 hour less because mktime
function uses locale, i.e. gmt+1, convert struct tm
seconds (tm_isdst
set -1 mktime
detects daylight savings etc. automatically).
any ideas how solve issue?
use _mkgmtime
/timegm
complement mktime
.
time_t mkgmtime(struct tm* tm) { #if defined(_win32) return _mkgmtime(tm); #elif defined(linux) return timegm(tm); #endif }
Comments
Post a Comment