我需要获取完整月份名称的短月份名称。
例如,
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."。我怎么能做到这一点?
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)
| 归档时间: |
|
| 查看次数: |
18762 次 |
| 最近记录: |