⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 peldatetime.pas

📁 delphi编写与Palm数据交换管道连接程序。
💻 PAS
字号:
unit pelDateTime;

interface

function UnixTimeToDateTime(const lw: LongWord): TDateTime;
function DateTimeToUnixTime(const lw: TDateTime):LongWord;

function UTCTimeToDateTime(const lw: LongWord): TDateTime;
function DateTimeToUTCTime(const lw: TDateTime):LongWord;

Function PalmDTToDateTime(const lw:LongWord):TDateTime;
function DateTimeToPalmDT(const lw: TDateTime):LongWord;

function PalmTimeToUTCTime(const lw: LongWord):LongWord;
function UTCTimeToPalmDT(const lw: LongWord):LongWord;

Function DateTimeAsStr(const lw:TDateTime):string;

function DateTimeToTimSeconds(DateTime:TDateTime):LongWord;
function TimSecondsToDateTime(ts: LongWord): TDateTime;

implementation
Uses
  windows,Sysutils;
const
  unixdayone = 25569.0; // 1970-01-01
  nineteen0four=1462.0; // 1904-01-01

function DateTimeToPalmDT(const lw: TDateTime):LongWord;
begin
  result := trunc((lw-nineteen0four)*secsperday)
end;

Function PalmDTToDateTime(const lw:LongWord):TDateTime;
begin
  result:=nineteen0four+(lw/secsperday);
end;

Function GetTimeZoneBias:longint;
var
  TimeZoneInformation: TTimeZoneInformation;
begin
  if GetTimeZoneInformation(TimeZoneInformation)= TIME_ZONE_ID_DAYLIGHT then
  begin
    result:=TimeZoneInformation.bias+TimeZoneInformation.DaylightBias;
  end
  else
  begin
    result:=TimeZoneInformation.bias;
  end;
end;

function UnixTimeToDateTime(const lw: LongWord): TDateTime;
begin
  result := unixdayone + (lw / secsperday);
end;

function DateTimeToUnixTime(const lw: TDateTime):LongWord;
begin
  result := trunc((lw-unixdayone)*secsperday);
end;

function DateTimeToUTCTime(const lw: TDateTime):LongWord;
//var
//  bias:Longint;
begin
  result := trunc((lw-unixdayone)*secsperday)+(GetTimeZoneBias*60);
end;

function UTCTimeToDateTime(const lw: LongWord): TDateTime;
begin
  result := unixdayone + ((Integer(lw)-(GetTimeZoneBias*60)) / secsperday);
end;

function PalmTimeToUTCTime(const lw: LongWord):LongWord;
begin
  result:=DateTimeToUTCTime(PalmDTToDateTime(lw));
end;

function UTCTimeToPalmDT(const lw: LongWord):LongWord;
begin
  result:=DateTimeToPalmDT(UTCTimeToDateTime(lw));
end;

Function DateTimeAsStr(const lw:TDateTime):string;
begin
  Result := FormatDateTime('yyyy-mm-dd hh":"mm":"ss ', lw);
end;

function DateTimeToTimSeconds(DateTime:TDateTime):LongWord;
const
  SecsPerDay = 24 * 60 * 60;
begin
  if DateTime < EncodeDate(1904, 1, 1) then
    raise Exception.Create('Invalid date to DateTimeToTimSeconds');

  if DateTime = 0 then
    Result := 0
  else
    Result := ((Trunc(DateTime) - Trunc(EncodeDate(1904, 1, 1))) * SecsPerDay)
      + Round(frac(DateTime)*SecsPerDay);
end;

function TimSecondsToDateTime(ts: LongWord): TDateTime;
const
  SecsPerDay = 24 * 60 * 60;
begin
  Result := EncodeDate(1904, 1, 1) + (ts div SecsPerDay) +
    ((ts mod SecsPerDay) / SecsPerDay);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -