编程技术 · 2022年8月15日

MySql的时间字段和DotNetC#中的DateTime字段转换

MySQL转换为C#中的时间
示例代码:
DateTime pStartTime = new DateTime(1970, 1, 1);
pStartTime = pStartTime.ToLocalTime();
DateTime pValue = pStartTime.AddSeconds(mysqltime);
return pValue;

C#转换为MySql中的时间(其实是int型字段)
DateTime pStartTime = new DateTime(1970, 1, 1);
pStartTime = pStartTime.ToLocalTime();
TimeSpan pTS = DateTime.Now.ToLocalTime().Subtract(pStartTime);
mysqltime = Convert.ToInt32(pTS.TotalSeconds);  //即1970-1-1开始的秒数

最新电影,电视剧,尽在午夜剧场

电影电视剧午夜不寂寞