ServiceStack CsvSerializer date format
Asked Answered
M

1

5

Using CsvSerializer as a static class. All of my dates are being output with the UTC Offset:

2017-09-05T01:51:52-07:00

The dates being fed in are UTC, I want the offset removed, so the output would be

2017-09-05T01:51:52

Code is being called as

CsvSerializer.SerializeToStream(data, outputStream);

I have tried using the following JsConfig settings with no luck:

JsConfig.DateHandler = DateHandler.DCJSCompatible;
JsConfig.AssumeUtc = true;
JsConfig.AppendUtcOffset = false;

Maybe I'm just using them incorrectly? How can I use the static CsvSerializer and get the dates output in the format I need?

Manipular answered 5/9, 2017 at 18:47 Comment(0)
P
6

You can override how Date's are serialized with:

JsConfig<DateTime>.SerializeFn = date => date.ToString("yyyy-MM-dd hh:mm:ss");
Palladic answered 5/9, 2017 at 22:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.