There are already right answers here but let me try to explain a little bit deeper..
Since there is no Console.WriteLine(DateTime)
overload, your code will call Console.WriteLine(object)
overload and for DateTime
type, this method will generate G
standard format specifier representation of your CurrentCulture
.
That means the combination of your ShortDatePattern
and LongTimePattern
properties is MM/dd/yyyy hh:mm:ss tt
of your CurrentCulture
.
And from this result you get, your CurrentCulture
has /
as a DateSeparator
and :
as a TimeSeparator
which is great for the results you want. You will not need to use another IFormatProvider
to generate exact results because of these separators.
Just format your value with custom date and time format specifiers like;
Console.WriteLine("{0:MM/dd/yyyy HH:mm:ss}", BirthDate); // 12/30/2015 00:00:00
Console.WriteLine("{0:MM/dd/yyyy}", BirthDate); // 12/30/2015
or use DateTime.ToString()
method which is equal;
Console.WriteLine(BirthDate.ToString("MM/dd/yyyy HH:mm:ss")); // 12/30/2015 00:00:00
Console.WriteLine(BirthDate.ToString("MM/dd/yyyy");// 12/30/2015