EN
C# / .NET - convert DateTime to mm/dd/yyyy
10 points
In C# / .NET it is possible to convert DateTime
object to MM/dd/yyyy formatted string in few ways.
xxxxxxxxxx
1
DateTime now = DateTime.Now;
2
3
Console.WriteLine(now.ToString("MM/dd/yyyy"));
Output:
xxxxxxxxxx
1
08/14/2019
Note: DateTime.ToString
method uses format description - see for other examples here.
xxxxxxxxxx
1
DateTime now = DateTime.Now;
2
3
Console.WriteLine(string.Format("{0:MM/dd/yyyy}", now));
Output:
xxxxxxxxxx
1
08/14/2019
Note: String.Format
method uses argument index and format description delimited with ":" character - see for other examples here.