| Larry W. Virden 2007-02-21, 7:10 pm |
| On Feb 8, 3:13 pm, vanos...@cox.net wrote:
> You will have to do the individual mappings as you said. However,
> once you have
> that its easy. For each area, set the TZ enviornment variable to the
> right
> timezone and then using something like strftime() to print out the
> current
> time in the format you choose.
Okay, i put together a prototype, just to figure out how to use the
various functions to try to generate times and dates for various
timezones. Here's the prototype's code. The problem is that the
tzset() call and putenv do not seem to be working:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
int main(int argc, char **argv)
{
struct tm tval;
time_t clock;
int i, size;
char timestamp[4096];
tval.tm_sec =59;
tval.tm_min =59; /* 01:59:59 am */
tval.tm_hour=01;
tval.tm_mday=11;
tval.tm_mon =02; /* 03/11/2007 */
tval.tm_year=107;
clock = mktime(&tval);
if (clock == (time_t) -1) {
perror("tsttz");
return 1;
}
if (argc < 2) {
fprintf(stderr, "USAGE: %s TZ_value\n", argv[0]);
return 2;
}
for (i=1; i <= argc-1; i++) {
putenv(argv[i]);
tzset();
size = strftime(timestamp, sizeof(timestamp),
"%T %A, %B %d, %Y %Z", &tval);
if (size < 0) {
perror("tsttz");
fprintf(stderr, "%s: failed in strftime\n",
argv[0]);
}
fprintf(stdout, "%s\n", timestamp);
}
return 0;
}
I compile the above, then run it as:
tsttz :US/Pacific
and what I get out is
01:59:59 Sunday, March 11, 2007 EST
which isn't what I was expecting - I was expecting PST ...
Can someone point out (hopefully gently) what I'm missing here.
My intent is to evolve this so that I start out with a time in one of
the timezones, then show what that time maps to in multiple
timezones...
|