Set DateTimeZoneHandling
on JsonSerializerSettings
to Utc
. That will convert all dates to UTC before serializing them.
public void SerializeObjectDateTimeZoneHandling()
{
string json = JsonConvert.SerializeObject(
new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified),
new JsonSerializerSettings
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc
});
Assert.AreEqual(@"""2000-01-01T01:01:01Z""", json);
}
Documentation: DateTimeZoneHandling setting
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…