{"id":1268,"date":"2024-08-20T13:20:19","date_gmt":"2024-08-20T12:20:19","guid":{"rendered":"https:\/\/blog.c-hase.de\/?p=1268"},"modified":"2024-08-20T13:20:19","modified_gmt":"2024-08-20T12:20:19","slug":"eigenes-jsonserialize-datetime-format","status":"publish","type":"post","link":"https:\/\/blog.c-hase.de\/?p=1268","title":{"rendered":"Eigenes JSONSerialize DAteTime Format"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You could use this approach:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class DateFormatConverter : IsoDateTimeConverter\n{\n    public DateFormatConverter(string format)\n    {\n        DateTimeFormat = format;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And use it this way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class ReturnObjectA \n{\n    &#91;JsonConverter(typeof(DateFormatConverter), \"yyyy-MM-dd\")]\n    public DateTime ReturnDate { get;set;}\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>DateTimeFormat<\/code> string uses the .NET format string syntax described here: <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/standard\/base-types\/custom-date-and-time-format-strings\">https:\/\/learn.microsoft.com\/en-us\/dotnet\/standard\/base-types\/custom-date-and-time-format-strings<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You could use this approach: And use it this way: The DateTimeFormat string uses the .NET format string syntax described here: https:\/\/learn.microsoft.com\/en-us\/dotnet\/standard\/base-types\/custom-date-and-time-format-strings<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1268","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/1268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1268"}],"version-history":[{"count":1,"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/1268\/revisions"}],"predecessor-version":[{"id":1269,"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=\/wp\/v2\/posts\/1268\/revisions\/1269"}],"wp:attachment":[{"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.c-hase.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}