如何从完整的月份名称中获取短月份名称?

WP_*_*ane 2 .net c# datetime

我需要获取完整月份名称的短月份名称。

例如,

DateTime.Now.ToString("MMMM", CultureInfo.CurrentCulture);
this returns - "agosto"

DateTime.Now.ToString("MMM", CultureInfo.CurrentCulture);
this returns - "ago."
Run Code Online (Sandbox Code Playgroud)

这两个代码仅用于获取当前月份。我需要获取所有月份的短月份名称。

如果我给"agosto",它应该返回"ago."。我怎么能做到这一点?

Raw*_*ing 7

一种替代Soner答案不使用一个循环:

public static string GetAbbreviatedFromFullName(string fullname)
{
    DateTime month;
    return DateTime.TryParseExact(
            fullname,
            "MMMM",
            CultureInfo.CurrentCulture,
            DateTimeStyles.None,
            out month)
        ? month.ToString("MMM")
        : null;
}
Run Code Online (Sandbox Code Playgroud)