本文整理汇总了C#中System.Globalization.DateTimeFormatInfo.GetMonthGenitiveName方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeFormatInfo.GetMonthGenitiveName方法的具体用法?C# DateTimeFormatInfo.GetMonthGenitiveName怎么用?C# DateTimeFormatInfo.GetMonthGenitiveName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.DateTimeFormatInfo
的用法示例。
在下文中一共展示了DateTimeFormatInfo.GetMonthGenitiveName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToString
//.........这里部分代码省略.........
if (tokLen <= 2)
DateTimeUtils.ZeroPad (result, dfi.Calendar.GetDayOfMonth (dt), tokLen == 1 ? 1 : 2);
else if (tokLen == 3)
result.Append (dfi.GetAbbreviatedDayName (dfi.Calendar.GetDayOfWeek (dt)));
else
result.Append (dfi.GetDayName (dfi.Calendar.GetDayOfWeek (dt)));
saw_day_specifier = true;
break;
case 'M':
// Month.m(m?) = month # (with leading 0 if two mm)
// mmm = 3 letter name
// mmmm+ = full name
tokLen = DateTimeUtils.CountRepeat (format, i, ch);
int month = dfi.Calendar.GetMonth(dt);
if (tokLen <= 2)
DateTimeUtils.ZeroPad (result, month, tokLen);
else if (tokLen == 3)
result.Append (dfi.GetAbbreviatedMonthName (month));
else {
// Handles MMMM dd format
if (!saw_day_specifier) {
for (int ii = i + 1; ii < format.Length; ++ii) {
ch = format [ii];
if (ch == 'd') {
saw_day_specifier = true;
break;
}
if (ch == '\'' || ch == '"') {
ii += ParseQuotedString (format, ii, null) - 1;
}
}
}
// NOTE: .NET ignores quoted 'd' and reads it as day specifier but I think
// that's wrong
result.Append (saw_day_specifier ? dfi.GetMonthGenitiveName (month) : dfi.GetMonthName (month));
}
break;
case 'y':
// Year. y(y?) = two digit year, with leading 0 if yy
// yyy+ full year with leading zeros if needed.
tokLen = DateTimeUtils.CountRepeat (format, i, ch);
if (tokLen <= 2)
DateTimeUtils.ZeroPad (result, dfi.Calendar.GetYear (dt) % 100, tokLen);
else
DateTimeUtils.ZeroPad (result, dfi.Calendar.GetYear (dt), tokLen);
break;
case 'g':
// Era name
tokLen = DateTimeUtils.CountRepeat (format, i, ch);
result.Append (dfi.GetEraName (dfi.Calendar.GetEra (dt)));
break;
//
// Other
//
case ':':
result.Append (dfi.TimeSeparator);
tokLen = 1;
break;
case '/':
result.Append (dfi.DateSeparator);
tokLen = 1;
break;
case '\'': case '"':
tokLen = ParseQuotedString (format, i, result);
break;
case '%':
if (i >= format.Length - 1)
throw new FormatException ("% at end of date time string");
if (format [i + 1] == '%')
throw new FormatException ("%% in date string");
// Look for the next char
tokLen = 1;
break;
case '\\':
// C-Style escape
if (i >= format.Length - 1)
throw new FormatException ("\\ at end of date time string");
result.Append (format [i + 1]);
tokLen = 2;
break;
default:
// catch all
result.Append (ch);
tokLen = 1;
break;
}
i += tokLen;
}
return result.ToString ();
}