Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new DateTime() vs default(DateTime)

People also ask

What is the default DateTime?

The default and the lowest value of a DateTime object is January 1, 0001 00:00:00 (midnight).

What is the default format of DateTime in C#?

The custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'".

What is DateTime MinValue in C#?

The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar. MinValue defines the date and time that is assigned to an uninitialized DateTime variable. The following example illustrates this. C# Copy.

What is DateTime now in C#?

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time. public: static property DateTime Now { DateTime get(); }; C# Copy.


No, they are identical.

default(), for any value type (DateTime is a value type) will always call the parameterless constructor.


If you want to use default value for a DateTime parameter in a method, you can only use default(DateTime).

The following line will not compile:

    private void MyMethod(DateTime syncedTime = DateTime.MinValue)

This line will compile:

    private void MyMethod(DateTime syncedTime = default(DateTime))

The answer is no. Keep in mind that in both cases, mdDate.Kind = DateTimeKind.Unspecified.

Therefore it may be better to do the following:

DateTime myDate = new DateTime(1, 1, 1, 0, 0, 0, DateTimeKind.Utc);

The myDate.Kind property is readonly, so it cannot be changed after the constructor is called.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!