user386258 user386258 - 1 year ago 77
C# Question

Best way to get the current month number in C#

I am using C# to get current month number:

string k=DateTime.Now.Month.ToString();

For January it will return
, but I need to get
. If December is the current month, I need to get
. Which is the best way to get this in C#?

Answer Source
string sMonth = DateTime.Now.ToString("MM");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download