delphi 13位时间戳互转

//获取13或10位时间戳 时区固定了 好像有问题
function Gettamptime(vlen: Integer): string;
var
timen, time2: TDateTime;
ss2, ss3: Int64;
begin
timen := now;
time2 := EncodeDateTime(1970, 1, 1, 0, 0, 0, 0);
ss2 := 28800000;
ss3 := MilliSecondsBetween(timen, time2);
ss3 := ss3 - ss2;
Result := InttoStr(ss3);
if vlen = 13 then
Result := Result
else if vlen = 10 then
Result := Copy(Result, 1, 10);
end;
///////////////标准正确的//////////////////////

function Gettamptime2(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 gettamptotime(vtamp: string): string;
//1582688206607
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 @ 2020-05-13 14:37  黑贝是条狗  阅读(2317)  评论(0编辑  收藏  举报