Article View: comp.os.msdos.programmer
Article #6282BC++ time related Global Variables - need Help
From: Michael Alan Corn
Date: Mon, 16 Nov 1992 00:53
Date: Mon, 16 Nov 1992 00:53
58 lines
2395 bytes
2395 bytes
This is probably too simply for you C/C++ gurus out there, but how does
one set the global variables for timezone and day light savings in BC++?
The following doesn't work:
misc includes
extern long timezone;
extern int daylight;
long getuservalue(void);
main()
{
time_t t;
struct tm *gmt;
timezone = getuservalue();
daylight = 1; //default is 0;
t = time(NULL);
localtime(&t);
gmt = gmtime(&t);
printf("GMT is: %s",asctime(gmt));
return 0;
}
No matter what value is entered for timezone, the gmt value doesn't change.
Since the gmt is a function of localtime, timezone, and daylight, it should
change. If the above code (with appropriate #includes) is run, the gmt
computed is the same regardless of the value timezone is set to, or the value
of daylight. Using the tzset alternative has little value as well:
main()
{
time_t t;
struct tm *gmt1, *gmt2;
char *tzstr1 = "TZ=PST8";
char *tzstr2 = "TZ=PST8PDT";
putenv(tzstr1);
tzset();
t = time(NULL);
localtime(&t);
gmt1 = gmtime(&t);
putenv(tzstr2);
tzset();
t = time(NULL);
localtime(&t);
gmt2 = gmtime(&t);
printf("gmt1 = %s, gmt2 = %s",asctime(gmt1),asctime(gmt2));
return 0;
}
I've yet to get the gmt, or any other time function to respond differently by
any setting of the "TZ" variable, save for the middle number. So if someone
could please explain, either what I'm doing wrong,( I'd like to have the user
enter the difference between gmt and local time, and whether daylight savings
is in effect, and set the appropriate values myself), or confirm something is
amiss, I would be greatly indebted. I wouldn't even complain if Borland
responded, since I've already spent 90 min. on hold over the last week and
have given up on tech support. Post or email to macg9505@uxa.cso.uiuc.edu
Thanks in advance. Mike
Technical Details
Message-ID:
<BxsAGt.4CG@news.cso.uiuc.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!pmafire!mica.inel.gov!ux1!news.byu.edu!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!macg9505Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!pmafire!mica.inel.gov!ux1!news.byu.edu!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!macg9505 From: macg9505@uxa.cso.uiuc.edu (Michael Alan Corn) Subject: BC++ time related Global Variables - need Help Message-ID: <BxsAGt.4CG@news.cso.uiuc.edu> Sender: usenet@news.cso.uiuc.edu (Net Noise owner) Organization: University of Illinois at Urbana Date: Mon, 16 Nov 1992 00:53:15 GMT Lines: 59