EN
C# / .NET - convert DateTime to yyyymmdd
3 points
In C# / .NET it is possible to convert DateTime
object to yyyyMMdd formatted string in few ways.
xxxxxxxxxx
1
DateTime now = DateTime.Now;
2
3
Console.WriteLine(now.ToString("yyyyMMdd"));
Output:
xxxxxxxxxx
1
20190814
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:yyyyMMdd}", now));
Output:
xxxxxxxxxx
1
20190814
Note: String.Format
method uses argument index and format description delimited with ":" character - see for other examples here.