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();
}
}get

public class UserInfo
{
public DateTime CreateTime { get; set; }
}string

相關文章
相關標籤/搜索