Best way to serialize a date without a year [Answered]
I want to serialize a date, ideally in such a way that it could be deserialized into a
DateOnly
. I don't really need the year, and I would also like to be able to include February 29, so I can't just serialize it as "02-29"
or something as that is year 0001. Is there any good way of serializing a specific date like this?5 Replies
Maybe whatever you are using to serialize allows for custom converters, if so you could use that as an in between step to get the format you want.
It might also be useful to create your own struct with one byte for the month and one byte for the day. You can then add a conversion step to the DateOnly. Just spitballing the first things that come to mind
That could work I suppose
And I'm using System.Text.Json which does support custom converters
I mean you say you don't really need the year, but if you want to have
02-29
included, then you kinda need it, no? Well... I guess
✅ This post has been marked as answered!