asp.net实现UNIX 时间戳
//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);
Response.Write(timeStamp);
//2将UNIX时间戳转换成系统时间
string
timeStamp = this.txtDate.Text;
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);
Response.Write(dtResult);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。