Running dateon my server results in the correct time. But using localtime() in C(++) I’m getting the wrong time.
Running date: Fr 30. Nov 12:15:36 CET 2012
Using localtime(): Fr 30 Nov 2012 11:15:36 CET
What’s wrong here?
OS: Debian 5.0.10
Some code:
struct tm* today;
today = localtime(...);
strftime(timeBuffer,50,myConnection.getMetaData().getDateFormat().c_str(),today);
The
struct tmreturned bylocaltimehas atm_isdstfield that indicates whether daylight saving time (DST) is in effect. You need to take that field into account when formatting the time.Try using
asctimeto format the time eg. :