Skip to content

Instantly share code, notes, and snippets.

@cxxr
Created July 14, 2017 19:34
Show Gist options
  • Save cxxr/6220cf30fefaf09ca7b022be984cc92d to your computer and use it in GitHub Desktop.
Save cxxr/6220cf30fefaf09ca7b022be984cc92d to your computer and use it in GitHub Desktop.
C# date madness
static void Main()
{
var date1 = DateTime.Parse("2017-07-14T19:00:00.0000000-07:00");
var date2 = DateTime.UtcNow; // <- today at "19:09:56" UTC or "12:09:56" PDT
Console.WriteLine(date1 > date2); // False <-- what??
Console.WriteLine(date1.ToUniversalTime() > date2); // True
var nowStr = DateTime.UtcNow.ToString("o");
Console.WriteLine(nowStr); // "2017-07-14T19:09:56.0616752Z"
var date3 = DateTime.Parse(nowStr);
Console.WriteLine(date1 > date3); // True <-- this is more like it
Console.WriteLine(date1.ToUniversalTime() > date3); // True
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment