-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
Quick Reference GuideRelates to the misc/quick-reference-guides section of the handbookRelates to the misc/quick-reference-guides section of the handbookgood first issue
Description
dotnet only has a DateTime and sometimes we want fields to just report a date.
Try this code to see if we can demonstrate how to format on both send and receive of api data as just a date:
[DataType(DataType.Date)]
[JsonConverter(typeof(JsonDateConverter))]
public DateTime InstallationDate { get; set; }
Also define this class:
class JsonDateConverter : JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> DateTime.ParseExact(reader.GetString(),
"yyyy-MM-dd", CultureInfo.InvariantCulture);
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(
"yyyy-MM-dd", CultureInfo.InvariantCulture));
}
Metadata
Metadata
Assignees
Labels
Quick Reference GuideRelates to the misc/quick-reference-guides section of the handbookRelates to the misc/quick-reference-guides section of the handbookgood first issue