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

    时间戳定义为从格林威治时间 1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。 

     C#格式时间转时间戳Timestamp

     private int GetCreatetime()  {

                    DateTime DateStart= new DateTime(1970,1,1,8,0,0);     

                   return Convert.ToInt32((DateTime.Now - DateStart).TotalSeconds);

     }  

    时间戳转为C#格式时间 

     private 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);  
    • }  
  • 相关阅读:
    053-606
    053-605
    1019 General Palindromic Number (20分)
    1208. 翻硬币
    754. 平方矩阵 II
    1346. 回文平方
    680. 剪绳子
    1227. 分巧克力
    756. 蛇形矩阵
    429. 奖学金
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/5871078.html
Copyright © 2011-2022 走看看