从discuz里面调取数据时,发现它的日期格式是UNIX时间戳格式,找到了两个转换成日期格式的方法
PHP转换
date("Y-m-d", $row["dateline"])
C#转换
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);