分享

c# 当前时间与数字互相转换

 五行和谐 2014-10-22

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类型数值还原为时间类型

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多