On 1/10/24 09:35:34, Dag-Erling Smørgrav via tz wrote:
Currently, strftime() implements %s by calling mktime() and then printing the result. This is fine when the struct tm passed to strftime() came from localtime() but not when it didn't. A better solution would be to call timegm() and then manually adjust the result. Of course that's only possible in the TM_GMTOFF case but that's still better than nothing. . This modification makes the two results equal, but I suspect it's not what you want. What is your input? What are you trying to do?
#include <stdlib.h> #include <stdio.h> #include <time.h> int main(void) { char buf[256]; time_t t; time(&t); strftime(buf, sizeof(buf), "%s %F %T %Z", localtime(&t)); printf("local\t%s\n", buf); putenv( "TZ=GMT0" ); strftime(buf, sizeof(buf), "%s %F %T %Z", gmtime(&t)); printf("gm\t%s\n", buf); } -- gil