• 【转】UNIX时间戳与.net日期类的转换


    1 将系统时间转换成UNIX时间戳
      DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));
      DateTime dtNow = DateTime.Parse(DateTime.Now.ToString());
      TimeSpan toNow = dtNow.Subtract(dtStart);
      string timeStamp = toNow.Ticks.ToString();
      timeStamp = timeStamp.Substring(0,timeStamp.Length - 7);

    2将UNIX时间戳转换成系统时间
      string timeStamp = "1144821796";
      DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));
      long lTime = long.Parse(timeStamp + "0000000");
      TimeSpan toNow = new TimeSpan(lTime);
      DateTime dtResult = dtStart.Add(toNow);

    //===================================

    //DateTime转变为UNIX时间,直接转换,不改变时区
    DateTime dtStart = new DateTime(1970, 1, 1, 0, 0, 0);
    TimeSpan toNow = dt.Subtract(dtStart);
    int timeStamp = (int)(toNow.Ticks/10000000);

    //===================================

     
    转自:http://blog.163.com/i_lcw/blog/static/87809734200926118577/
     
     
     
    http://cache.baiducontent.com/c?m=9d78d513d99000ed4fece4690d61c0676908d7252bd6a00209d1843be0735a31193dbffc6d351174c4b40f7071ac5e2c9be74174234460e99492ce0c9fac935b32956271350b8636488048f6911b7a9637902db8f246fac1ac66ceca89849a49208a155e2bdea79c5d7415ca64f51f26e3d1c30e4a01&p=882a9545d29407eb44b0c7710f5788&newp=8b2a975f8a9c11a058ed9066464c9d231610db2151d1d3116588cc&user=baidu&fm=sc&query=asp%2Enet%D7%AAlinux%CA%B1%BC%E4&qid=&p1=7


    1 将系统时间转换成UNIX时间戳
    DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));
    DateTime dtNow = DateTime.Parse(DateTime.Now.ToString());
    TimeSpan toNow = dtNow.SuBTract(dtStart);
    string timeStamp = toNow.Ticks.ToString();
    timeStamp = timeStamp.Substring(0,timeStamp.Length - 7);2将UNIX时间戳转换成系统时间
    string timeStamp = "1144821796";
    DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));
    long lTime = long.Parse(timeStamp + "0000000");
    TimeSpan toNow = new TimeSpan(lTime);
    DateTime dtResult = dtStart.Add(toNow);
    短短几行代码,却花了我几个小时,就因为时区的问题,@_@
  • 相关阅读:
    JSP学习笔记(7)JSP的文件操作 璃月
    【XML】xStream浅录 璃月
    Centos 7 安装后设置 璃月
    Dom解析xml 璃月
    mysql5.7.13.zip安装(windows) 璃月
    Oracle定时任务小案例 璃月
    mysql 慢查询日志相关参数,及慢sql分析
    mysql调优的几个参数
    数据库中1是true 0 是false
    mysql sql语句选错索引可以尝试的解决方案
  • 原文地址:https://www.cnblogs.com/nhlinkin/p/3601068.html
Copyright © 2020-2023  润新知