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

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