Search code examples
c#servicestackjson-deserialization

ServiceStack JsConfig.Init DateHandler to Local Time


I'm using JsConfig.Init(new Config {DateHandler = DateHandler.UnixTimeMs}); as was previously suggested and it's deserializing now but the times are all wrong due to it assuming UTC rather than local time.

How do I tell the deserializer to assume local time rather than UTC so my times are correct?


Solution

  • Unix TimeStamps assumes UTC as per their definition - containing the number of seconds from Unix Epoch on January 1st, 1970 at UTC.

    ServiceStack's default Date format uses WCF Date Format which contains a timeoffset that deserializes back into Local DateTime by default, why don't you stick to using the default?

    Otherwise you can to convert the UTC DateTime to Local Time yourself with .ToLocalTime()