關於SystemTimeToTzSpecificLocalTime的問題 |
尚未結案
|
jjkk86
一般會員 發表:8 回覆:6 積分:2 註冊:2005-01-02 發送簡訊給我 |
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
第一個參數是指向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@瞭解越多.懂得越少@ |
jjkk86
一般會員 發表:8 回覆:6 積分:2 註冊:2005-01-02 發送簡訊給我 |
引言: 第一個參數是指向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.aspchris_shieh你好: 由於小弟是初學者,所以有點看不太懂耶,可不可以請你說明一下程式的意思呢#include@瞭解越多.懂得越少@ |
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
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 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |