Delphi XE 时间和时间戳互转换【转】

复制代码
uses
  System.DateUtils;

function TForm1.Gettamptime(vlen: Integer): string;
var
ss:
string;
begin
if vlen = 13 then
begin
ss :
= DateTimeToTimeStamp(now).time.ToString;
Result :
= IntToStr(DateTimeToUnix(Now, false)) + Copy(ss, Length(ss) - 2, Length(ss));
end
else if vlen = 10 then
begin
Result :
= IntToStr(DateTimeToUnix(Now, false));
end
end;

function TForm1.GettampToTime(vtamp: string): string;
var
ls10, lms:
string;
begin
if Length(vtamp) = 10 then
Result :
= FormatDateTime('yyyy-MM-dd hh:mm:ss', UnixToDateTime(StrToInt64(vtamp), false))
else if Length(vtamp) = 13 then
begin
ls10 :
= Copy(vtamp, 1, 10);
lms :
= Copy(vtamp, 11, 13);
Result :
= FormatDateTime('yyyy-MM-dd hh:mm:ss', UnixToDateTime(StrToInt64(ls10), false));
Result :
= Result + '.' + lms;
end;
end;

复制代码

 

posted @ 2024-04-30 11:34  九日之阳  阅读(26)  评论(0编辑  收藏  举报