home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10702 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.2 KB  |  70 lines

  1. Path: sparky!uunet!ogicse!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!macg9505
  2. From: macg9505@uxa.cso.uiuc.edu (Michael Alan Corn)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: BC++ time related Global Variables
  5. Message-ID: <BxvAzo.2My@news.cso.uiuc.edu>
  6. Date: 17 Nov 92 15:57:20 GMT
  7. Article-I.D.: news.BxvAzo.2My
  8. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  9. Organization: University of Illinois at Urbana
  10. Lines: 58
  11.  
  12.  
  13.       
  14.       This is probably too simply for you C/C++ gurus out there, but how does
  15. one set the global variables for timezone and day light savings in BC++?
  16. The following doesn't work:
  17. misc includes
  18. extern long timezone;
  19. extern int  daylight;
  20. long getuservalue(void);
  21.  
  22. main()
  23. {
  24. time_t t;
  25. struct tm *gmt;
  26. timezone = getuservalue();
  27. daylight = 1;                 //default is 0;
  28. t = time(NULL);
  29. localtime(&t);
  30. gmt = gmtime(&t);
  31. printf("GMT is:    %s",asctime(gmt));
  32. return 0;
  33. }
  34.  
  35. No matter what value is entered for timezone, the gmt value doesn't change. 
  36. Since the gmt is a function of localtime, timezone, and daylight, it should
  37. change. If the above code (with appropriate #includes) is run, the gmt
  38. computed is the same regardless of the value timezone is set to, or the value
  39. of daylight.  Using the tzset alternative has little value as well:
  40.  
  41. main()
  42. {
  43. time_t t;
  44. struct tm *gmt1, *gmt2;
  45. char *tzstr1 = "TZ=PST8";
  46. char *tzstr2 = "TZ=PST8PDT";
  47. putenv(tzstr1);
  48. tzset();
  49. t = time(NULL);
  50. localtime(&t);
  51. gmt1 = gmtime(&t);
  52. putenv(tzstr2);
  53. tzset();
  54. t = time(NULL);
  55. localtime(&t);
  56. gmt2 = gmtime(&t);
  57. printf("gmt1 = %s, gmt2 = %s",asctime(gmt1),asctime(gmt2));
  58. return 0;
  59. }
  60.  
  61. I've yet to get the gmt, or any other time function to respond differently by
  62. any setting of the "TZ" variable, save for the middle number.  So if someone
  63. could please explain, either what I'm doing wrong,( I'd like to have the user
  64. enter the difference between gmt and local time, and whether daylight savings
  65. is in effect, and set the appropriate values myself), or confirm something is
  66. amiss, I would be greatly indebted.  I wouldn't even complain if Borland
  67. responded, since I've already spent 90 min. on hold over the last week and
  68. have given up on tech support. Post or email to macg9505@uxa.cso.uiuc.edu 
  69. Thanks in advance.  Mike
  70.