首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > PHP > PHP中的 dateline 转换成 c#中的 datetime 方法 UNIX时间转换

PHP中的 dateline 转换成 c#中的 datetime 方法 UNIX时间转换

  • 资源大小:1.10KB
  • 上传时间:2021-07-28
  • 下载次数:0次
  • 浏览次数:0次
  • 资源积分:1积分
  • 标      签: C#语言基础

资 源 简 介

在众多的PHP MySQL的应用之中,存储在MySQL中的时间都是一串数字,后经查这个格式的日期叫做:Unix Timestamp;Unix的timestamp是一组数字,表示从1970年1月1日以来的秒数。今天在进行C#应用开发时需要对MySQL中的数据进行操作,写出以下方法供大家参考。主要应用到的类库有:System.TimeZone应用的方法:返回对应于指定协调通用时间 (UTC) 的本地时间。public virtual DateTime ToLocalTime(   DateTime time);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 = "1176686120";            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);
VIP VIP
0.204577s