DateTimeToGreenUnix

@暗夜魔尊
{ Unix date conversion support with time-zone detect }

function DateTimeToGreenUnix(const AValue: TDateTime; MilliSeconds: Boolean = False): Int64;
var
tzi : TTimeZoneInformation;
GrDt: TDateTime;
begin
GetTimeZoneInformation(tzi);
GrDt := IncHour(AValue, tzi.Bias div 60);
if MilliSeconds then
Result := MilliSecondsBetween(UnixDateDelta, GrDt)
else
Result := SecondsBetween(UnixDateDelta, GrDt);
if GrDt < UnixDateDelta then
Result := -Result;
end;

function GreenUnixToDateTime(const AValue: Int64; MilliSeconds: Boolean = False): TDateTime;
var

tzi : TTimeZoneInformation;
begin
GetTimeZoneInformation(tzi);
if MilliSeconds then
Result := IncMilliSecond(UnixDateDelta, AValue - tzi.Bias * 60 * 1000)
else
Result := IncSecond(UnixDateDelta, AValue - tzi.Bias * 60);
end;

posted @ 2017-03-14 01:56  findumars  Views(322)  Comments(0Edit  收藏  举报