❔ problem with DateTime format
guys, the "[DisplayFormat(DataFormatString = "{dd/MM/yyyy}")]" is not working for me:
when i add an event or update it, still shows like this
{
"title": "string",
"description": "string",
"date": "2023-08-28T22:43:42.452Z",
"attendees": [
"string"
]
}
can somebody help me?
20 Replies
Database entities should never be concerned with how they're represented.
I'd even argue, they should not be represented period, but rather selected into a DTO
Also, it's possible that this attribute simply doesn't work with JSON serialization
I'd say, the date should be sent as ISO8601 like it happens now, and it should be the concern of the frontend to display it in whatever format is desired
i tried that
for some reason it still doesnt work
so i came with this idea
but i dont know if it is a good practice
i created a class DateTimeConverter
Well, if you really want, you could have the
Date
be a string
and convert the format during selectionand i added to the program.cs
What I wonder, though, is why not pass the date like it should be
In ISO8601 format
And let the frontend worry about formatting
its just the specification for this internship project i got
Ah, oof, my condolences
otherwise i would keep it
Schools and companies utilize the shittiest standards sometimes
yeah
In that case, do this
so, i came with that solution
.
is this ok?
Does it work?
it does
haha
Then it's fine
just dont know if they will look at it and find strange or bad practices
Not using ISO8601 is a bad practice already
And they clearly don't care
So
hmm
yeah
ok then
Even then, this is how you would do it
Whatever you needed to format, tapping into the converter options will do the trick
And it's fine
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.