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!
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!
public static DateTime StartOfRecordedHistory = new DateTime(2004, 1, 1)
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.
Using
public static DateTime StartOfRecordedHistory = new DateTime(2004, 1, 1)
is probably the best way as, as it's been pointed out, it doesn't have any issues with different date-time formats.
There are numerous creators for a DateTime - see the MSDN documentation, so you can have the exact format of date you want.