当前年份
|
起始年份
|
基准值
|
输入年份03
|
输入年份50
|
输入年份68
|
1998
|
0
|
1900
|
1903
|
1950
|
1968
|
2002
|
0
|
2000
|
2003
|
2050
|
2068
|
1998
|
50
|
1948
|
2003
|
1950
|
1968
|
2000
|
50
|
1950
|
2003
|
1950
|
1968
|
2002
|
50
|
1952
|
2003
|
2050
|
1968
|
2020
|
50
|
1970
|
2003
|
2050
|
2068
|
2020
|
10
|
2010
|
2103
|
2050
|
2068
|
Delphi的DateTimeToUnix/UnixToDateTime转换时间并没有考虑到本地时间和格林尼治时间的差,结果我天朝时间被赤裸裸的差了8个小时.
type
time_t =
Int64
;
function
DateTimeToUnix(ConvDate: TDateTime): time_t;
var
zi : TTimeZoneInformation;
begin
GetTimeZoneInformation(zi);
Result := Round((ConvDate - UnixDateDelta) *
86400
) +
60
*(zi
.
Bias + zi
.
DaylightBias);
end
;
function
UnixToDateTime(USec: time_t): TDateTime;
var
zi : TTimeZoneInformation;
begin
GetTimeZoneInformation(zi);
Result := ((USec -
60
*zi
.
Bias) /
86400
) + UnixDateDelta;
end
;
====================================
//相关函数: SysUtils.DateTimeToTimeStamp(); SysUtils.TimeStampToDateTime(); SysUtils.TimeStampToMSecs(); SysUtils.MSecsToTimeStamp(); Windows.GetTickCount; Windows.GetCurrentTime; {GetCurrentTime 和 GetTickCount 一样, 是调用了 GetTickCount.}
TTimeStamp = record Time: Integer; { "毫秒" 表示的时间, 自: 0:0:0:0 } Date: Integer; { "天" 表示的日期, 自: 1/1/0001 } end; {TDateTime 与 TTimeStamp 互相转换的例子} var T: TDateTime; TS: TTimeStamp; begin T := EncodeDateTime(2009, 5, 22, 11, 22, 33, 999); TS := DateTimeToTimeStamp(T); ShowMessage(IntToStr(TS.Time)); //40953999; 当日已逝去了 40953999 毫秒 ShowMessage(IntToStr(TS.Date)); //733549; 自 0001-1-1 的第 733549 天 T := TimeStampToDateTime(TS); ShowMessage(FormatDateTime('yyyy-m-d h:m:s:z', T)); //2009-5-22 11:22:33:999 end;
{TimeStampToMSecs、MSecsToTimeStamp 示例:} var T: TDateTime; TS: TTimeStamp; ms: Comp; {这是 TimeStampToMSecs 返回的类型} begin T := EncodeDateTime(2009, 5, 22, 11, 22, 33, 999); TS := DateTimeToTimeStamp(T); ms := TimeStampToMSecs(TS); ShowMessage(FloatToStr(ms)); //63378674553999 TS := MSecsToTimeStamp(ms); T := TimeStampToDateTime(TS); ShowMessage(FormatDateTime('yyyy-m-d h:m:s:z', T)); //2009-5-22 11:22:33:999 end;
{获取开机时间的例子} var T1: Int64; T2,T3: Comp; T4: TDateTime; begin T1 := GetTickCount; {从开机到现在的毫秒数} T2 := TimeStampToMSecs(DateTimeToTimeStamp(Now)); {从 0001-1-1 到当前时间的毫秒数} T3 := T2 - T1; {从 0001-1-1 到开机时刻的毫秒数} T4 := TimeStampToDateTime(MSecsToTimeStamp(T3)); {从 0001-1-1 到开机时刻的时间} ShowMessage(DateTimeToStr(T4)); {显示开机时间} end;