user-0 提问: 守护进程调用程序，两个程序时间相差8个小时

回复:
user: user-1
content: _tzset Sets time environment variables.  void _tzset( void );  Routine Required Header Compatibility  _tzset <time.h> Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  None  Remarks  The _tzset function uses the current setting of the environment variable TZ to assign values to three global variables: _daylight, _timezone, and _tzname. These variables are used by the _ftime and localtime functions to make corrections from coordinated universal time (UTC) to local time, and by the time function to compute UTC from system time. Use the following syntax to set the TZ environment variable:  set TZ=tzn[+ | –]hh[:mm[:ss] ][dzn]  tzn  Three-letter time-zone name, such as PST. You must specify the correct offset from local time to UTC.  hh  Difference in hours between UTC and local time. Optionally signed.  mm  Minutes. Separated from hh by a colon (:).  ss  Seconds. Separated from mm by a colon (:).  dzn  Three-letter daylight-saving-time zone such as PDT. If daylight saving time is never in effect in the locality, set TZ without a value for dzn. The C run-time library assumes the United States’s rules for implementing the calculation of Daylight Saving Time (DST).   For example, to set the TZ environment variable to correspond to the current time zone in Germany, you can use one of the following statements:  set TZ=GST-1GDT set TZ=GST+1GDT  These strings use GST to indicate German standard time, assume that Germany is one hour ahead of UTC, and assume that daylight savings time is in effect.  If the TZ value is not set, _tzset attempts to use the time zone information specified by the operating system. Under Windows NT and Windows 95, this information is specified in the Control Panel’s Date/Time application. If _tzset cannot obtain this information, it uses PST8PDT by default, which signifies the Pacific time zone.   Based on the TZ environment variable value, the following values are assigned to the global variables _daylight, _timezone, and _tzname when _tzset is called:  Global Variable Description Default Value  _daylight Nonzero value if a daylight-saving-time zone is specified in TZ setting; otherwise, 0 1  _timezone Difference in seconds between UTC and local time. 28800 (28800 seconds equals 8 hours)  _tzname[0] String value of time-zone name from TZ environmental variable; empty if TZ has not been set PST  _tzname[1] String value of daylight-saving-time zone; empty if daylight-saving-time zone is omitted from TZ environmental variable PDT    The default values shown in the preceding table for _daylight and the _tzname array correspond to “PST8PDT.” If the DST zone is omitted from the TZ environmental variable, the value of _daylight is 0 and the _ftime, gmtime, and localtime functions return 0 for their DST flags.   Example  /* TZSET.C: This program first sets up the time zone by  * placing the variable named TZ=EST5 in the environment  * table. It then uses _tzset to set the global variables  * named _daylight, _timezone, and _tzname.  */  #include <time.h> #include <stdlib.h> #include <stdio.h>  void main( void ) {    if( _putenv( "TZ=EST5EDT" ) == -1 )    {       printf( "Unable to set TZ\n" );       exit( 1 );    }    else    {       _tzset();       printf( "_daylight = %d\n", _daylight );       printf( "_timezone = %ld\n", _timezone );       printf( "_tzname[0] = %s\n", _tzname[0] );    }    exit( 0 ); }   Output  _daylight = 1 _timezone = 18000 _tzname[0] = EST   Time Management Routines  See Also   asctime, _ftime, gmtime, localtime, time, _utime

user: user-1
content: localtime Converts a time value and corrects for the local time zone.  struct tm *localtime( const time_t *timer );  Routine Required Header Compatibility  localtime <time.h> ANSI, Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  localtime returns a pointer to the structure result. If the value in timer represents a date before midnight, January 1, 1970, localtime returns NULL. The fields of the structure type tm store the following values, each of which is an int:  tm_sec  Seconds after minute (0 – 59)  tm_min  Minutes after hour (0 – 59)  tm_hour  Hours after midnight (0 – 23)  tm_mday  Day of month (1 – 31)  tm_mon  Month (0 – 11; January = 0)  tm_year  Year (current year minus 1900)  tm_wday  Day of week (0 – 6; Sunday = 0)  tm_yday  Day of year (0 – 365; January 1 = 0)  tm_isdst  Positive value if daylight saving time is in effect; 0 if daylight saving time is not in effect; negative value if status of daylight saving time is unknown. The C run-time library assumes the United States’s rules for implementing the calculation of Daylight Saving Time (DST).   Parameter  timer  Pointer to stored time  Remarks  The localtime function converts a time stored as a time_t value and stores the result in a structure of type tm. The long value timer represents the seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC). This value is usually obtained from the time function.  gmtime, mktime, and localtime all use a single statically allocated tm structure for the conversion. Each call to one of these routines destroys the result of the previous call.  localtime corrects for the local time zone if the user first sets the global environment variable TZ. When TZ is set, three other environment variables (_timezone, _daylight, and _tzname) are automatically set as well. See _tzset for a description of these variables. TZ is a Microsoft extension and not part of the ANSI standard definition of localtime.  Note   The target environment should try to determine whether daylight saving time is in effect.  Example  /* LOCALTIM.C: This program uses time to get the current time   * and then uses localtime to convert this time to a structure   * representing the local time. The program converts the result   * from a 24-hour clock to a 12-hour clock and determines the   * proper extension (AM or PM).  */  #include <stdio.h> #include <string.h> #include <time.h>  void main( void ) {         struct tm *newtime;         char am_pm[] = "AM";         time_t long_time;          time( &long_time );                /* Get time as long integer. */         newtime = localtime( &long_time ); /* Convert to local time. */          if( newtime->tm_hour > 12 )        /* Set up extension. */                 strcpy( am_pm, "PM" );         if( newtime->tm_hour > 12 )        /* Convert from 24-hour */                 newtime->tm_hour -= 12;    /*   to 12-hour clock.  */         if( newtime->tm_hour == 0 )        /*Set hour to 12 if midnight. */                 newtime->tm_hour = 12;          printf( "%.19s %s\n", asctime( newtime ), am_pm ); }   Output  Tue Mar 23 11:28:17 AM   Time Management Routines  See Also   asctime, ctime, _ftime, gmtime, time, _tzset

user: user-0
content: 引用 2 楼 user-2 的回复:东八区和gmt时间的区别。 但是同样获取时间的方式为什么两个程序得到的时间不一样呢

user: user-0
content: 引用 1 楼 zhao4zhong1 的回复:也许只是因为北京的时区是东八区。 没看懂，现在就是系统时间就是正确的，程序就像上面说的那个状况

user: user-2
content: 东八区和gmt时间的区别。

user: user-1
content: 也许只是因为北京的时区是东八区。