吴旭晓个人博客 繁体中文 简体中文

首页| 日志 |JAVA |ASP |PHP |Android |IOS |ASP.NET |JavaScript |DIV+CSS |SEO |taobaoke |饼哥语录
繁体中文 简体中文

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);

作者:吴旭晓 | 来源:个人博客 | 点击量:2012 | 发布时间:2013-08-19
最新留言 | 返回上一页 | 返回首页

相关文章:

版权所有:吴旭晓个人博客 Copyright © 2013-2023 个人博客