所有DateTime是否存儲這樣的數據庫後:發出不正確的日期應用程序重啓
myDate.ToUniversalTime()
我可以看到日期被正確地存儲在UTC格式的數據庫,即。
當我從Xamarin中創建的Android應用程序使用參數創建對象時,新創建的對象將返回到應用程序,並且UTC時間在該對象中正確發回。
但是,當我關閉應用程序時,同一個對象現在有另一個時間戳,即不是UTC時間戳。
App
- >CreatePayment(int amount)
- >ASP.NET MVC
這是否有魔力,並返回應用程序的新創建對象以保存在本地。
在示例對象中,返回日期爲21/10/2016 21:53:01
。
現在我重新啓動應用程序,返回的日期值爲22/10/2016 4:53:01
。
這怎麼會發生?
我是否需要設置一些設置,以便ASP.NET MVC知道從數據庫加載的日期是UTC格式?
可以Application_BeginRequest
導致這些問題與我的設置?
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["Language"];
if (cookie != null && cookie.Value != null)
{
var abbrivation = cookie.Value;
Thread.CurrentThread.CurrentCulture = new CultureInfo(abbrivation);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(abbrivation);
}
else
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("es");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es");
}
}
感謝您的回答。實際上我已經有了這一行,並且我從Application_BeginRequest中刪除了邏輯,但不正確的日期仍然發出。我認爲它不應該與文化有任何關係,對吧?我的意思是,它只應該發送一個日期。 – Jefecito
您可能會看看我更新的答案中提到的頁面。 –