Delphi XE 时间和时间戳互转换  
官方Delphi 学习QQ群: 682628230(三千人)
频道

Delphi XE 时间和时间戳互转换


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;

1812875-20210608150904169-1169472707.png

来源:https://www.cnblogs.com/redhat588/p/14862897.html


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.10996007919312 seconds