Best way to get a static DateTime value
10,925
Solution 1
public static DateTime StartOfRecordedHistory = new DateTime(2004, 1, 1)
Solution 2
public static readonly DateTime StartOfRecordedHistory = new DateTime(2004, 1, 1);
No more elegant, I admit, but it avoids any issues with locale-dependent date parsing.
If you're looking for date-time literals, unfortunately C# doesn't provide them.
Comments
-
Jannie Theunissen about 2 years
Is there a better way to get a static DateTime value in C# than the following?
public static DateTime StartOfRecordedHistory = DateTime.Parse("2004-01-01");
Thanks!