zoukankan      html  css  js  c++  java
  • UNIX 时间戳 C#

    /// 将Unix时间戳转换为DateTime类型时间
    /// </summary>
    /// <param name="d">double 型数字</param>
    /// <returns>DateTime</returns>
    public static System.DateTime ConvertIntDateTime(double d)
    {
    System.DateTime time = System.DateTime.MinValue;
    System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
    time = startTime.AddMilliseconds(d);
    return time;
    }

    /// <summary>
    /// 将c# DateTime时间格式转换为Unix时间戳格式
    /// </summary>
    /// <param name="time">时间</param>
    /// <returns>long</returns>
    public static long ConvertDateTimeInt(System.DateTime time)
    {
    //double intResult = 0;
    System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
    //intResult = (time- startTime).TotalMilliseconds;
    long t = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
    return t;
    }

  • 相关阅读:
    Python #面向对象
    Python #@property属性
    Linux # screen 用法
    Shell #监控进程脚本
    Linux # nethogs
    Python #logging
    Python #time
    Python # 一个api接口调用POST请求
    Python # 和风天气接口
    IP地址的组成
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/4034844.html
Copyright © 2011-2022 走看看