Created
March 17, 2023 13:30
-
-
Save luebster/22a3fabda0100859fda9fe485ac8f02e to your computer and use it in GitHub Desktop.
Comparing "Now" to local datetimes in C# that makes the most sense to me
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a DateTime in UTC Time | |
DateTime _startDate = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime("3/12/2023 20:00:00"), TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); | |
// Use UTC Now to compare UTC datetimes | |
DateTime _now = DateTime.UtcNow; | |
bool nowIsBefore = _now < _startDate; | |
bool nowIsEqual = _now == _startDate; | |
bool nowIsAfter = _now > _startDate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment