0

This is a Xamarin Forms app.

In some part of the code, I am transfering an object to a Web Api 2 service.

The object is serialized using this:

            var json = JsonConvert.SerializeObject(new
            {
                item.Codigo,
                registro.Fecha,
                Latitud = registro.Posicion.Latitude,
                Longitud = registro.Posicion.Longitude,
                Altitud = registro.Posicion.Altitude
            });

Where registro.Fecha contains a date and time.

If that variable is, for example, 25th July 2019 at 07:02 P.M.

The date and time is serialized this way:

2019-07-25T19:02:09.53052+08:00

How can I get rid of that "+08:00"? That causes the Web Api application store the data as 25th July 2019 at 07:02 A.M.. My country is at UTC-4. I think that is why the server store the data with +12 hours in difference.

When using a REST tester, I pass the parameter without the "+08:00" and it works.

How can I solve this?

I tried by adding

        var userSelectedCulture = new System.Globalization.CultureInfo("es-CL");
        System.Threading.Thread.CurrentThread.CurrentCulture = userSelectedCulture;

in MainActivity OnCreate method but it did not work.

Regards Jaime

jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • 4
    use UTC times to avoid ambiguity – Jason Jul 25 '19 at 23:37
  • *registro.Fecha contains a date and time.* - then can you share code showing a case where `registro.Fecha` is initialized and the output is wrong -- i.e. a [mcve]? Probably using `DateTimeZoneHandling.Utc` will fix your problem but we can't say for sure without a concrete example. See: [Can you tell JSON.Net to serialize DateTime as Utc even if unspecified?](https://stackoverflow.com/a/10305908/3744182). – dbc Jul 26 '19 at 04:01
  • https://stackoverflow.com/questions/37257964/removing-time-zone-offset-from-datetimeoffset – Morse Jul 26 '19 at 16:31

0 Answers0