zoukankan      html  css  js  c++  java
  • c# 当前时间与数字互相转换

    1,1900年1月1日

    DateTime oldtime = Convert.ToDateTime("1900-1-1 00:00:00");//构造1900年1月1日
    TimeSpan ts
    = DateTime.Now.Subtract(oldtime);//计算从1900年1月1日到现在的时间间隔
    double num = ts.TotalSeconds;//计算出此间隔的总的秒数
    Response.Write(num
    +"<br/>");
    DateTime numtodate = oldtime.AddSeconds(num);//在1900年1月1日基础上添加这个秒数,还原成时间
    Response.Write(numtodate.ToString());


    2,0000年1月1日

     

    DateTime time = new DateTime(2005,12,5);
            Response.Write("ticks:" + time.Ticks+"<br/>");
            Response.Write("time:"+new DateTime(time.Ticks));

    DateTime time = new DateTime(2005,12,5);  //构造2005年12月5日的时间类型

    Response.Write("ticks:" + time.Ticks+"<br/>"); //time.Ticks为0000年1月1日到2005年12月5日的long类型数值,单位为100豪微秒

     Response.Write("time:"+new DateTime(time.Ticks));//new DateTime(time.Ticks)由long类型数值还原为时间类型

  • 相关阅读:
    CF995A Tesla
    CF961D Pair Of Lines
    P1186 玛丽卡
    CF986B Petr and Permutations
    hdu6331 Problem M. Walking Plan
    Edison UVALive3488
    Be a Smart Raftsman SGU475
    100198H Royal Federation
    100197G Robbers
    Evil Book -- CodeChef
  • 原文地址:https://www.cnblogs.com/zmxmiss/p/1719428.html
Copyright © 2011-2022 走看看