線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:5059
推到 Plurk!
推到 Facebook!

關於SystemTimeToTzSpecificLocalTime的問題

尚未結案
jjkk86
一般會員


發表:8
回覆:6
積分:2
註冊:2005-01-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-26 16:56:40 IP:211.73.xxx.xxx 未訂閱
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal); 如果要把世界時轉換成美國時間NULL要改成什麼ㄋ?? 發表人 - taishyang 於 2005/01/26 17:29:08
chris_shieh
高階會員


發表:46
回覆:308
積分:240
註冊:2004-04-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-27 11:52:11 IP:219.68.xxx.xxx 未訂閱
第一個參數是指向TIME_ZONE_INFORMATION的指標 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/time_zone_information_str.asp 利用SetTimeZoneInformation設定TIME_ZONE_INFORMATION http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/settimezoneinformation.asp
#include 
#include 
#include     void main()
{
   TIME_ZONE_INFORMATION tziOld, tziNew, tziTest;
   DWORD dwRet;       dwRet = GetTimeZoneInformation(&tziOld);       if( dwRet == TIME_ZONE_ID_STANDARD )    
      wprintf(L"%s\n", tziOld.StandardName);
   else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
      wprintf(L"%s\n", tziOld.DaylightName);
   else
   {
      printf("GTZI failed (%d)\n", GetLastError());
      return;
   }       ZeroMemory(&tziNew, sizeof(tziNew));
   tziNew.Bias = tziOld.Bias   60;
   wcscpy(tziNew.StandardName, L"Test Standard Zone");
   tziNew.StandardDate.wMonth = 10;
   tziNew.StandardDate.wDayOfWeek = 0;
   tziNew.StandardDate.wDay = 5;
   tziNew.StandardDate.wHour = 2;       wcscpy(tziNew.DaylightName, L"Test Daylight Zone");
   tziNew.DaylightDate.wMonth = 4;
   tziNew.DaylightDate.wDayOfWeek = 0;
   tziNew.DaylightDate.wDay = 1;
   tziNew.DaylightDate.wHour = 2;
   tziNew.DaylightBias = -60;       if( !SetTimeZoneInformation( &tziNew ) ) 
   {
      printf("STZI failed (%d)\n", GetLastError());
      return;
   }       dwRet = GetTimeZoneInformation(&tziNew);       if( dwRet == TIME_ZONE_ID_STANDARD )    
      wprintf(L"%s\n", tziNew.StandardName);
   else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
      wprintf(L"%s\n", tziNew.DaylightName);
   else
      printf("GTZI failed (%d)\n", GetLastError());
}
@瞭解越多.懂得越少@
jjkk86
一般會員


發表:8
回覆:6
積分:2
註冊:2005-01-02

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-02-15 20:45:23 IP:211.73.xxx.xxx 未訂閱
引言: 第一個參數是指向TIME_ZONE_INFORMATION的指標 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/time_zone_information_str.asp 利用SetTimeZoneInformation設定TIME_ZONE_INFORMATION http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/settimezoneinformation.asp
#include 
#include 
#include     void main()
{
   TIME_ZONE_INFORMATION tziOld, tziNew, tziTest;
   DWORD dwRet;       dwRet = GetTimeZoneInformation(&tziOld);       if( dwRet == TIME_ZONE_ID_STANDARD )    
      wprintf(L"%s\n", tziOld.StandardName);
   else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
      wprintf(L"%s\n", tziOld.DaylightName);
   else
   {
      printf("GTZI failed (%d)\n", GetLastError());
      return;
   }       ZeroMemory(&tziNew, sizeof(tziNew));
   tziNew.Bias = tziOld.Bias   60;
   wcscpy(tziNew.StandardName, L"Test Standard Zone");
   tziNew.StandardDate.wMonth = 10;
   tziNew.StandardDate.wDayOfWeek = 0;
   tziNew.StandardDate.wDay = 5;
   tziNew.StandardDate.wHour = 2;       wcscpy(tziNew.DaylightName, L"Test Daylight Zone");
   tziNew.DaylightDate.wMonth = 4;
   tziNew.DaylightDate.wDayOfWeek = 0;
   tziNew.DaylightDate.wDay = 1;
   tziNew.DaylightDate.wHour = 2;
   tziNew.DaylightBias = -60;       if( !SetTimeZoneInformation( &tziNew ) ) 
   {
      printf("STZI failed (%d)\n", GetLastError());
      return;
   }       dwRet = GetTimeZoneInformation(&tziNew);       if( dwRet == TIME_ZONE_ID_STANDARD )    
      wprintf(L"%s\n", tziNew.StandardName);
   else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
      wprintf(L"%s\n", tziNew.DaylightName);
   else
      printf("GTZI failed (%d)\n", GetLastError());
}
@瞭解越多.懂得越少@
chris_shieh你好: 由於小弟是初學者,所以有點看不太懂耶,可不可以請你說明一下程式的意思呢
chris_shieh
高階會員


發表:46
回覆:308
積分:240
註冊:2004-04-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-03-11 14:57:13 IP:218.167.xxx.xxx 未訂閱
GetTimeZoneInformation(&tziOld) 可以取得目前電腦的TimeZoneInformation    ZeroMemory(&tziNew, sizeof(tziNew)); 建立一個新的TimeZoneInformation    TimeZoneInformation中bias的定義 UTC = local time + bias     tziNew.Bias = tziOld.Bias + 60;  指定該新時區的時間偏移為 tziOld 加上 60 分鐘 如果舊時區是台灣(GMT+8, bias=-8) 新時區是美國(GMT-8, bias=+8) tziNew.Bias = tziOld.Bias + 2*8*60;  (-8 -> +8)    所以你要轉換為美國某時區時間 就需要先得到該時區的TimeZoneInformation 如果當地就是美國時間當然直接用GetTimeZoneInformation取得 不然就是上面方式轉換取得    以下為一應用SystemTimeToTzSpecificLocalTime的函式範例 (Delphi) 該函式接受某時區的時間轉換為另一時區的時間    
function UTCToLocalTime( UTCTime : TDateTime; iTimeZoneBias:integer ): TDateTime;
var
  LocalSTime, UTCSTime : TSystemTime;
  TZInfo : TTimeZoneInformation;
  PTZInfo : PTimeZoneInformation;
  CalcResult : LongBool;
  LastError : LongInt;
begin       GetTimeZoneInformation( TzInfo );
   Tzinfo.bias := Tzinfo.bias   iTimeZoneBias*60;
   PTZInfo := @TZInfo;       DateTimeToSystemTime( UTCTime, UTCSTime );
   CalcResult := SystemTimeToTzSpecificLocalTime( PTzInfo, UTCSTime,
LocalSTime );
   if not CalcResult then begin
      LastError := GetLastError;
      raise Exception.Create(SysErrorMessage(LastError));
   end;       Result := SystemTimeToDateTime( LocalSTime );    end;    example:    台灣時間(GMT 8, bias=-8)轉換為美國當地時間(GMT-8, bias= 8):
UTCToLocalTime(now, 16);    美國時間(GMT-8, bias= 8)轉換為台灣當地時間(GMT 8, bias=-8):
UTCToLocalTime(now, -16);
@瞭解越多.懂得越少@ 發表人 - chris_shieh 於 2005/03/11 15:25:46
系統時間:2024-04-18 19:41:47
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!