|
Add
Keep origional date with XML UTC Format
I didn't find any simple clean solutions online, so I am posting this for any others that have this problem. Solution to adjust the time. UTC format adds a Bias time on to the end of the time format. So all you need to do is get the Bias for the time coming in and the Bias for the current computer and then adjust the time after calling XMLTimeToDateTime. Code - Hopefully I didn't forget anything in stripping this out. Uses XSBuiltIns, IdGlobalProtocols, DateUtils, Windows; procedure TDateInput.SetDateXml(const Value: String); var curAdj : Integer; adjDiff : Integer; XSDateTime : TXSDateTime; tz : TTimeZoneInformation; begin adjDiff := 0 if value <> '' then begin XSDateTime := TXSDateTime.Create; try XSDateTime.XSToNative(Value); adjDiff := XSDateTime.HourOffset; case getTimeZoneInformation(tz) of TIME_ZONE_ID_STANDARD: curAdj := -(tz.StandardBias + tz.Bias) div 60; TIME_ZONE_ID_DAYLIGHT: curAdj := -(tz.DaylightBias + tz.Bias) div 60; else curAdj := -(tz.Bias div 60); end; adjDiff := adjDiff - curAdj; finally XSDateTime.Free; end; end; Self.fDate := XMLTimeToDateTime(value); fDate := IncHour(fDate, adjDiff); end;
Related Discussions
|
Latest News
Latest Forum Entries
|