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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM