DateTime.Month.ToString("MMM")无效

Jam*_*son 1 c# datetime console-application

我从SQL中获取日期:

2009-10-28 11:17:06.690
Run Code Online (Sandbox Code Playgroud)

我将它放入DateTime并用SQL中的值填充它:

DateTime createdDate;
createdDate = reader.GetDateTime(1);
Run Code Online (Sandbox Code Playgroud)

然后我想写出这个月,所以我这样做:

var fileMonth = createdDate.Month.ToString("MMM");
Run Code Online (Sandbox Code Playgroud)

此时代码fileMonth现在="MMM"而不是"Oct".

我在这做错了什么?

Joe*_*orn 9

.Month属性只是一个整数,它对DateTime格式一无所知.你需要的只是这个:

var fileMonth = createdDate.ToString("MMM");
Run Code Online (Sandbox Code Playgroud)