✅ Creating a datetime with a timezone
How do I create a
DateTime
with new DateTime(2010, 05, 12);
and give it a specific TimeZoneInfo
19 Replies
I dont think DateTime can hold time zone that would be DateTimeOffset
best u can get would be doing UTC
and then using TimeZoneInfo
yeah got it, but then how would I get the time of the first day of the month?
I'd want to get like 01/03/2024 at 00:00 in the specific timezone
get as in what sense? querying a db? just represent it in the datatime object or what?
because if you're getting it from the db u would be doing so in UTC as well so I dont see the problem
in DB and server side it would be UTC, just that the clients work on their own time zone
ok and what db is it?
postgres
so it uses DateTimeOffset
anyways DB doesn't matter, it's all UTC
there is no need for offset
I just want the client app to have it's own timezone and I'll convert to UTC when sending to server
sure then u would just use TimeZoneInfo
to offset it
say like I want to gather reports from 01/01/2024 to 31/01/2024 as CEST time
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
and DTO can output me a DT as UTC anyways
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
alright
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
ok so I'll just create an offset based on a DateOnly
Worht mentioning that offset isn't a timezone, for all of the pedantics out there. That's a lossy conversion going from one to the other.