zoukankan      html  css  js  c++  java
  • C# Datetime.Ticks将时间转换成以秒为单位与格林尼治时间

    转载于:http://blog.csdn.net/tyxkzzf/article/details/49132237

    在编程前要知道C#中TimeSpan.Ticks到底是多大:
    TICK最小的时间单位刻度,相当于100奈秒(1奈秒等于十亿分之一秒)。刻度可正可负。
    下面举个C#例子计算下两个日期的时间差吧。
    DateTime dt = new DateTime(1970, 1, 1);
    TimeSpan d =DateTime.Parse("2011/12/24 9:41:40")- dt;
    long seconddiff =d.Ticks/10000000;
    计算得到的d.ticks的单位为奈秒,要转换成秒就必须除以1000000000;计算结果为1324719700;
    那反过来已知日期,求与这个日期相差的N秒的日期,就是先将已经日期的秒数求出,再与相差的秒数相加就可以了。
    求与日期为1970年1月1日相差秒数为1324719700的日期是多少?
    DateTime dt = new DateTime(1970, 1, 1);
    DateTime ts=dt.AddSeconds(1324719700);
    MessageBox.Show(ts.ToString ("yyyy/MM/dd hh:mm:ss"));
    得到结果为2011/12/24 9:41:40

  • 相关阅读:
    POJ 1095 Trees Made to Order 最详细的解题报告
    Producter and Consumer
    How to use the function of bind
    How to use the functions of apply and call
    Configurate vim tool
    #4713. 方程
    #4709. 树
    #4718. 管理
    #4710. 并
    #4707. 点分治
  • 原文地址:https://www.cnblogs.com/xinbaba/p/7194091.html
Copyright © 2011-2022 走看看