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

    /// <summary>
    /// 获取当前本地时间戳
    /// </summary>
    /// <returns></returns>      
    public long GetCurrentTimeUnix()
    {
    	TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)));
    	long t = (long)cha.TotalSeconds;
    	return t;
    }
    /// <summary>
    /// 时间戳转换为本地时间对象
    /// </summary>
    /// <returns></returns>      
    public DateTime GetUnixDateTime(long unix)
    {
    	//long unix = 1500863191;
    	DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
    	DateTime newTime=  dtStart.AddSeconds(unix);
    	return newTime;
    }
    

      

  • 相关阅读:
    毕设(五)ListView
    毕设(四)ListBox
    毕设(三)NotifyIcon
    hdu 1.2.3
    ZOJ 1789 The Suspects
    ZOJ 2833 Friendship
    git
    yum wget rpm
    上传绕过
    LAMP 和 LNMP
  • 原文地址:https://www.cnblogs.com/fogwang/p/8491144.html
Copyright © 2011-2022 走看看