I have a server set to EST and am wondering what I need to do to create a DateTimeOffset set to Midnight of the current day but in a different timezone? For example PST?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
TimeZoneInfo.DateTimewhich contains the local time (i.e. midnight)TimeZoneInfo.GetUtcOffsetto find the offset from UTCDateTimeOffsetwith the local time and the offset(If Noda Time were production-ready, I’d suggest creating a
ZonedDateTimeusing that, but unfortunately we’re not even close to ready for v1 yet… although actually the bits you’d need are probably stable enough 🙂It’s worth noting that “midnight of the current day” doesn’t always exist in all time zones. If you may need to deal with time zones which have a DST transition at midnight, you may want to look at
TimeZoneInfo.IsAmbiguousTimeandTimeZoneInfo.IsInvalidTime.