zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    【Linux高频命令专题(7)】rm
    【Linux高频命令专题(6)】mkdir
    【mongoDB运维篇①】用户管理
    【Linux高频命令专题(5)】rmdir
    【mongoDB中级篇②】索引与expain
    【mongoDB中级篇①】游标cursor
    Lua中的字符串函数库
    ngx_lua 随笔
    Nginx与Lua
    MAC 上搭建lua
  • 原文地址:https://www.cnblogs.com/iwana/p/12882211.html
Copyright © 2011-2022 走看看