zoukankan      html  css  js  c++  java
  • C# 的时间戳转换

    今天有时间戳转换的需求,网上找了半天才找到相关代码,经测试有效,特作此笔记和大家分享!

    1.时间戳转为C#格式时间

    复制代码
           /// <summary>
            /// 时间戳转为C#格式时间
            /// </summary>
            /// <param name="timeStamp">Unix时间戳格式</param>
            /// <returns>C#格式时间</returns>
            public static DateTime GetTime(string timeStamp)
            {
                DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long lTime = long.Parse(timeStamp + "0000000");
                TimeSpan toNow = new TimeSpan(lTime);
                return dtStart.Add(toNow);
            }
    复制代码

    2.DateTime时间格式转换为Unix时间戳格式

    复制代码
            /// <summary>
            /// DateTime时间格式转换为Unix时间戳格式
            /// </summary>
            /// <param name="time"> DateTime时间格式</param>
            /// <returns>Unix时间戳格式</returns>
            public static int ConvertDateTimeInt(System.DateTime time)
            {
                System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                return (int)(time - startTime).TotalSeconds;
            }
  • 相关阅读:
    makefile中宏定义
    make的静态模式
    makefile中两重if判断
    定义命令包
    嵌套执行make
    AcWing 1014. 登山
    AcWing 482. 合唱队形
    AcWing 1027. 方格取数
    AcWing 1016. 最大上升子序列和
    AcWing 187. 导弹防御系统
  • 原文地址:https://www.cnblogs.com/Mwsoft/p/3867914.html
Copyright © 2011-2022 走看看