In my app, I convert user-specified time into time_t
format and store it. At a later point, I display this time in local time zone. Here is my test code:
int main() {
const char* INPUTFMT = "%b %d, %Y %H:%M:%S %Z";
const char* SAMPLETIME = "Feb 19, 2016 01:00:00 EST";
struct tm tm = {0};
char* val = strptime(SAMPLETIME, INPUTFMT, &tm);
time_t st = mktime(&tm);
const struct tm* t1 = localtime(&st);
static const char* OUTPUTFMT = "%b %d, %G %I:%M:%S %p %Z";
char buf[100];
strftime (buf, 100, OUTPUTFMT, t1);
printf("%s\n", buf);
return 0;
}
The specified timezone is EST and my local timezone is PST.
The problem I am running into is that, although my local timezone is different than the one specified, I see the same time except that EST is replaced by PST.
I am wondering what is it that I am doing wrong. Regards.