-1

All DateTimes are stored like this in the database:

myDate.ToUniversalTime()

I can see the dates are stored correctly in the database i.e. in UTC format.

When I, from an Android application created in Xamarin, create an object using parameters the newly created object is returned to the application and the UTC time is sent back correctly in that object.

However, when I close the app the same object does now have another timestamp i.e. not the UTC time stamp.

App -> CreatePayment(int amount) -> ASP.NET MVC does it's magic and returns the newly created object for the app to save locally.

In an example object the returned date was 21/10/2016 21:53:01.

Now I restart the app and the returned date value is 22/10/2016 4:53:01.

How could this happen?

Do I need to set some setting so that ASP.NET MVC knows that the dates loaded from the database are in UTC format?

Can Application_BeginRequest cause these problems with my settings?

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");
            }
        }
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Westerlund.io
  • 2,743
  • 5
  • 30
  • 37

1 Answers1

0

You can try to add <globalization> parameters in the web.config as shown below:

<system.web>
    <globalization culture="es-MX" uiCulture="es" />
</system.web>

On the other hand, if the problem cannot be solved by applying this settings, you might have a look at MVC - UTC date to LocalTime.

Murat Yıldız
  • 11,299
  • 6
  • 63
  • 63
  • Thanks for your answer. Actually I already had that line and I removed the logic from Application_BeginRequest but the incorrect date is still sent out. I don't think it should have anything to do with the culture, right? I mean, it should only send out a date. – Westerlund.io Oct 21 '16 at 22:54
  • You might have a look at the page mentioned on my updated answer. – Murat Yıldız Oct 22 '16 at 20:14