C#:DateTime.Now Month output format

DateTime.Now.Month.ToString("d2")

Either format the integer with two digits as suggested by Mehrdad, or format the DateTime itself to give you a two-digit month:

DateTime.Now.ToString("MM")

I'm using Selenium Webdriver to test a website and set various vars, strings, etc. at the beginning; this made it a lot simpler:

/* Date strings */
public static string TodayNum = DateTime.Now.ToString("dd");        // e.g 07
public static string ThisMonthNum = DateTime.Now.ToString("MM");    // e.g 03
public static string ThisMonthShort = DateTime.Now.ToString("MMM");  // e.g Mar
public static string ThisMonthLong = DateTime.Now.ToString("MMMM");  // e.g March
public static string ThisYearNum = DateTime.Now.ToString("yyyy");   // e.g 2014

Tags:

C#