C#对象先序列化然后反序列化时间丢失八小时的问题 ToLocalTime
class Program
{
static void Main(string[] args)
{
UserInfo userInfo = new UserInfo();
userInfo.CreateTime = DateTime.Now;
string userString = SlJson.ToJson(userInfo);//序列化
UserInfo userInfoAfter = SlJson.FromJson<UserInfo>(userString);//反序列化
Console.WriteLine("时间戳:" + userString);
Console.WriteLine("转换后:" + userInfoAfter.CreateTime);
Console.WriteLine("本地" + userInfoAfter.CreateTime.ToLocalTime());
Console.ReadKey();
}
}
public class UserInfo
{
public DateTime CreateTime { get; set; }
}