UTC时间转换为本地时间 UTCToLocalTime
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;根据时区设置本地时间;