• delphi java 日期 转换 获取Unix时间戳


    获取Unix时间戳

    http://www.cnblogs.com/findumars/p/4716753.html

    最简单准确一句话

     Result:=IntToStr(  DateTimeToUnix(now())-28800);

    系统自带的函数

    { Unix date conversion support }

    function DateTimeToUnix(const AValue: TDateTime; AInputIsUTC: Boolean = True): Int64;
    function UnixToDateTime(const AValue: Int64; AReturnUTC: Boolean = True): TDateTime;

    还有函数UnixToDateTime,在文件system.DateUtils

    c++builder

    // 将Java中的日期转换为Delphi中的日期
    TDateTime ConvertJavaDateTimeToDelphiDateTime(__int64 Value)
    {
        return IncMilliSecond(StrToDate("1970-1-1"), Value);
    }
    
    // 将Delphi中的日期转换为Java中的日期
    double ConvertDelphiDateTimeToJavaDateTime(TDateTime ADateTime)
    {
        return MilliSecondSpan(ADateTime, StrToDate("1970-1-1"));
    }

    1483927576698

        // pc端接收到的数据00 00 01 59 80 f9 e0 7a
        // 2017-01-09 02:06:16
        byte bta[8] = { 0x7a,0xe0,0xf9,0x80,0x59,0x01,0x00,0x00    };
        // byte bta[8] = {  0x00,0x00,0x01,0x59,0x80,0xf9,0xe0,0x7a    };
        double da = *(__int64*)&bta[0];
        TDateTime dtad;
        dtad = ConvertJavaDateTimeToDelphiDateTime(da);
        TDateTime dt1;
        dt1 = StrToDateTime("2017-01-09 02:06:16");
        double jv1;
        jv1 = ConvertDelphiDateTimeToJavaDateTime(dt1);
        byte bt1[8];
        memcpy(&bt1[0], (byte*)&jv1, 8);
    
        //check
    
        TDateTime dtad1;
         dtad1  = ConvertJavaDateTimeToDelphiDateTime(jv1);

       //2017-01-10 18:13:24

    0x38,0xAD,0x95,0x89,0x59,0x01,0x00,0x00

       __int64 jv=1484072004920;
           TDateTime dtad;
        dtad = ConvertJavaDateTimeToDelphiDateTime(jv);
        this->Caption =dtad.DateTimeString();

    var
      aint: int64;
      bs: array [0 .. 7] of byte;
      pb: PByteArray;
    begin
      aint := 1484072004920;
      pb := @aint;
      Move(aint, bs[0], 8);

    int64= Trunc(double val);

  • 相关阅读:
    vue vmodel input type=checkbox的问题
    springboot配置文件优先级
    原生js实现复制功能
    Long.valueOf和Long.parseLong的区别
    程序员学习参考
    国外开源项目
    .NET快速入门教程
    Microsoft Update Catalog 离线安装包下载
    php header示例代码
    CentOS下iptables设置
  • 原文地址:https://www.cnblogs.com/cb168/p/6269741.html
Copyright © 2020-2023  润新知