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 on 2021-06-08 15:09  redhat588  阅读(824)  评论(0编辑  收藏  举报