Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#:DateTime.Now Month output format

Tags:

c#

In this C# code snippet, DateTime.Now.Month.ToString() returns 7 as output.

I would like to get 07 as a return value.

What can I do to add the leading zero when the month has only 1 digit?

like image 904
Shyju Avatar asked Jul 20 '09 09:07

Shyju


1 Answers

DateTime.Now.Month.ToString("d2") 
like image 139
mmx Avatar answered Oct 07 '22 08:10

mmx