我想知道是否有办法让用户输入像01这样的数字,并使用dateTime将该字符串转换为月份.我知道如何让用户输入一个字符串,例如01/01/2011,并将其转换为DateTime.有没有办法使用datetime将两个数字字符串转换为一个月.像这样的东西,但那会奏效
Console.WriteLine("Please the month numerically");
string date = Console.ReadLine();
dt = Convert.ToDateTime(date).Month;
Run Code Online (Sandbox Code Playgroud)
Joa*_*son 21
但是,你可能会通过DateTime跳过一些箍;
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(int monthNumber);
Run Code Online (Sandbox Code Playgroud)
可能更容易.