您的位置:首页 > 其它

UTC时间转换为本地时间 UTCToLocalTime

2012-10-07 23:08 579 查看
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;根据时区设置本地时间;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐