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;
//主要用到两个重要的函数:
// GetTimeZoneInformation;得到时区信息
// SystemTimeToTzSpecificLocalTime;根据时区设置本地时间;
本文介绍了一种将UTC时间转换为本地时间的算法实现,使用Delphi中的GetTimeZoneInformation和SystemTimeToTzSpecificLocalTime函数来获取时区信息并进行时间转换。
3873

被折叠的 条评论
为什么被折叠?



