码迷,mamicode.com
首页 > 其他好文 > 详细

TimeStamp

时间:2014-07-22 23:09:53      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:blog   color   os   io   art   for   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
private void Form1_Load(object sender, EventArgs e)
      {
        textBox1.Text= GenerateTimeStamp(System.DateTime.Now);
        textBox2.Text = GetTime(textBox1.Text).ToString();
      }
      public string GenerateTimeStamp(DateTime dt)
      {
          // Default implementation of UNIX time of the current UTC time
          TimeSpan ts = dt.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0);
          return Convert.ToInt64(ts.TotalSeconds).ToString();
      }
      /// <summary>
      /// 时间戳转为C#格式时间
      /// </summary>
      /// <param name=”timeStamp”></param>
      /// <returns></returns>
      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);
      }
 
      /// <summary>
      /// DateTime时间格式转换为Unix时间戳格式
      /// </summary>
      /// <param name=”time”></param>
      /// <returns></returns>
      private int ConvertDateTimeInt(System.DateTime time)
      {
          System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
          return (int)(time - startTime).TotalSeconds;
      }

  

TimeStamp,码迷,mamicode.com

TimeStamp

标签:blog   color   os   io   art   for   

原文地址:http://www.cnblogs.com/vjiedao/p/3700303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!