Skip to main content
Some clarification
Source Link
Saeb Amini
  • 24.6k
  • 10
  • 85
  • 78

It can also be done with a tempan IsoDateTimeConverter instance, without changing global formatting settings:

string json = JsonConvert.SerializeObject(yourObject,
    new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });

This uses the JsonConvert.SerializeObject overload that takes a params JsonConverter[] argument.

It can also be done with a temp IsoDateTimeConverter instance, without changing global formatting settings:

string json = JsonConvert.SerializeObject(yourObject,
    new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });

This uses the overload that takes a params JsonConverter[] argument.

It can also be done with an IsoDateTimeConverter instance, without changing global formatting settings:

string json = JsonConvert.SerializeObject(yourObject,
    new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });

This uses the JsonConvert.SerializeObject overload that takes a params JsonConverter[] argument.

deleted 130 characters in body
Source Link
Saeb Amini
  • 24.6k
  • 10
  • 85
  • 78

FWIW, I was looking for a simple way to specify datetime formatting when serializing using JsonConvert.SerializeObject and found out itIt can also be done with a temp IsoDateTimeConverter instance, without changing global formatting settings:

string json = JsonConvert.SerializeObject(yourObject,
    new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });

This uses the overload that takes a params JsonConverter[] argument.

FWIW, I was looking for a simple way to specify datetime formatting when serializing using JsonConvert.SerializeObject and found out it can be done with a temp IsoDateTimeConverter instance, without changing global formatting settings:

string json = JsonConvert.SerializeObject(yourObject,
    new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });

This uses the overload that takes a params JsonConverter[] argument.

It can also be done with a temp IsoDateTimeConverter instance, without changing global formatting settings:

string json = JsonConvert.SerializeObject(yourObject,
    new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });

This uses the overload that takes a params JsonConverter[] argument.

Source Link
Saeb Amini
  • 24.6k
  • 10
  • 85
  • 78

FWIW, I was looking for a simple way to specify datetime formatting when serializing using JsonConvert.SerializeObject and found out it can be done with a temp IsoDateTimeConverter instance, without changing global formatting settings:

string json = JsonConvert.SerializeObject(yourObject,
    new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });

This uses the overload that takes a params JsonConverter[] argument.