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

分类: asp.net   出处:iocblog整理  更新时间:2008-05-26   添加到收藏  
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");[来源www.iocblog.net]
timespan tonow = new timespan(ltime);
datetime dtresult = dtstart.add(tonow);
短短几行代码,却花了我几个小时,就因为时区的问题,@_@



文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。