当前位置: 首页>>代码示例>>C#>>正文


C# DateTimeFormatInfo.GetEraName方法代码示例

本文整理汇总了C#中System.Globalization.DateTimeFormatInfo.GetEraName方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeFormatInfo.GetEraName方法的具体用法?C# DateTimeFormatInfo.GetEraName怎么用?C# DateTimeFormatInfo.GetEraName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Globalization.DateTimeFormatInfo的用法示例。


在下文中一共展示了DateTimeFormatInfo.GetEraName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatCustomized

        //
        //  FormatCustomized
        //
        //  Actions: Format the DateTime instance using the specified format.
        // 
        private static String FormatCustomized(DateTime dateTime, String format, DateTimeFormatInfo dtfi, TimeSpan offset) {


            Calendar cal = dtfi.Calendar;
            StringBuilder result = StringBuilderCache.Acquire();
            // This is a flag to indicate if we are format the dates using Hebrew calendar.

            bool isHebrewCalendar = (cal.ID == Calendar.CAL_HEBREW);
            // This is a flag to indicate if we are formating hour/minute/second only.
            bool bTimeOnly = true;
                        
            int i = 0;
            int tokenLen, hour12;
            
            while (i < format.Length) {
                char ch = format[i];
                int nextChar;
                switch (ch) {
                    case 'g':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        result.Append(dtfi.GetEraName(cal.GetEra(dateTime)));
                        break;
                    case 'h':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        hour12 = dateTime.Hour % 12;
                        if (hour12 == 0)
                        {
                            hour12 = 12;
                        }
                        FormatDigits(result, hour12, tokenLen);
                        break;
                    case 'H':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Hour, tokenLen);
                        break;
                    case 'm':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Minute, tokenLen);
                        break;
                    case 's':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Second, tokenLen);
                        break;
                    case 'f':
                    case 'F':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        if (tokenLen <= MaxSecondsFractionDigits) {
                            long fraction = (dateTime.Ticks % Calendar.TicksPerSecond);
                            fraction = fraction / (long)Math.Pow(10, 7 - tokenLen);
                            if (ch == 'f') {
                                result.Append(((int)fraction).ToString(fixedNumberFormats[tokenLen - 1], CultureInfo.InvariantCulture));
                            }
                            else {
                                int effectiveDigits = tokenLen;
                                while (effectiveDigits > 0) {
                                    if (fraction % 10 == 0) {
                                        fraction = fraction / 10;
                                        effectiveDigits--;
                                    }
                                    else {
                                        break;
                                    }
                                }
                                if (effectiveDigits > 0) {
                                    result.Append(((int)fraction).ToString(fixedNumberFormats[effectiveDigits - 1], CultureInfo.InvariantCulture));
                                }
                                else {
                                    // No fraction to emit, so see if we should remove decimal also.
                                    if (result.Length > 0 && result[result.Length - 1] == '.') {
                                        result.Remove(result.Length - 1, 1);
                                    }
                                }
                            }
                        } else {
                            throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                        }
                        break;
                    case 't':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        if (tokenLen == 1)
                        {
                            if (dateTime.Hour < 12)
                            {
                                if (dtfi.AMDesignator.Length >= 1)
                                {
                                    result.Append(dtfi.AMDesignator[0]);
                                }
                            }
                            else
                            {
                                if (dtfi.PMDesignator.Length >= 1)
                                {
                                    result.Append(dtfi.PMDesignator[0]);
                                }
                            }
//.........这里部分代码省略.........
开发者ID:afrog33k,项目名称:csnative,代码行数:101,代码来源:DateTimeFormat.cs

示例2: MatchEraName

		private static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
		{
			if (str.GetNext())
			{
				int[] eras = dtfi.Calendar.Eras;
				if (eras != null)
				{
					for (int i = 0; i < eras.Length; i++)
					{
						string text = dtfi.GetEraName(eras[i]);
						if (str.MatchSpecifiedWord(text))
						{
							str.Index += text.Length - 1;
							result = eras[i];
							return true;
						}
						text = dtfi.GetAbbreviatedEraName(eras[i]);
						if (str.MatchSpecifiedWord(text))
						{
							str.Index += text.Length - 1;
							result = eras[i];
							return true;
						}
					}
				}
			}
			return false;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:28,代码来源:DateTimeParse.cs

示例3: ToString


//.........这里部分代码省略.........
                    default:
                        {
                            format = nameProvider != null ? nameProvider.ShortDatePattern : dtfi.ShortDatePattern;

                            break;
                        }
                }
            }

            format = format.Replace(nameProvider != null ? nameProvider.DateSeparator : dtfi.DateSeparator, "/");

            StringBuilder sb = new StringBuilder();

            Calendar c = nameProvider != null ? nameProvider.Calendar : dtfi.Calendar;

            int i = 0;

            while (i < format.Length)
            {
                int tokLen;
                char ch = format[i];

                switch (ch)
                {
                    case 'd':
                        {
                            tokLen = CountChar(format, i, ch);

                            sb.Append(
                                tokLen <= 2
                                    ? DateMethods.GetNumberString(this.Day, nativeDigits, tokLen == 2)
                                    : GetDayName(c.GetDayOfWeek(this.Date), dtfi, nameProvider, tokLen == 3));

                            break;
                        }

                    case 'M':
                        {
                            tokLen = CountChar(format, i, ch);

                            sb.Append(
                                tokLen <= 2
                                    ? DateMethods.GetNumberString(this.Month, nativeDigits, tokLen == 2)
                                    : GetMonthName(this.Month, this.Year, dtfi, nameProvider, tokLen == 3));

                            break;
                        }

                    case 'y':
                        {
                            tokLen = CountChar(format, i, ch);

                            sb.Append(
                                tokLen <= 2
                                    ? DateMethods.GetNumberString(this.Year % 100, nativeDigits, true)
                                    : DateMethods.GetNumberString(this.Year, nativeDigits, false));

                            break;
                        }

                    case 'g':
                        {
                            tokLen = CountChar(format, i, ch);

                            sb.Append(nameProvider != null ? nameProvider.GetEraName(c.GetEra(this.Date)) : dtfi.GetEraName(c.GetEra(this.Date)));

                            break;
                        }

                    case '/':
                        {
                            tokLen = CountChar(format, i, ch);

                            sb.Append(nameProvider != null ? nameProvider.DateSeparator : dtfi.DateSeparator);

                            break;
                        }

                    case '\'':
                        {
                            tokLen = 1;

                            break;
                        }

                    default:
                        {
                            tokLen = 1;

                            sb.Append(ch.ToString(CultureInfo.CurrentUICulture));

                            break;
                        }
                }

                i += tokLen;
            }

            return sb.ToString();
        }
开发者ID:tu-tran,项目名称:FareLiz,代码行数:101,代码来源:MonthCalendarDate.cs

示例4: CreateDateInfoJson

 private static JObject CreateDateInfoJson(DateTimeFormatInfo di)
 {
     var obj = new
     {
         firstDay = di.FirstDayOfWeek,
         days = new
         {
             names = di.DayNames,
             namesAbbr = di.AbbreviatedDayNames,
             namesShort = di.ShortestDayNames
         },
         months = new
         {
             names = di.MonthNames,
             namesAbbr = di.AbbreviatedMonthNames
         },
         AM = di.AMDesignator,
         PM = di.PMDesignator,
         eras = di.Calendar.Eras.Select(era => new { offset = 0, start = (string)null, name = di.GetEraName(era) }).ToArray(),
         twoDigitYearMax = di.Calendar.TwoDigitYearMax,
         patterns = new
         {
             d = di.ShortDatePattern,
             D = di.LongDatePattern,
             t = di.ShortTimePattern,
             T = di.LongTimePattern,
             f = di.LongDatePattern + " " + di.ShortTimePattern,
             F = di.LongDatePattern + " " + di.LongTimePattern,
             M = di.MonthDayPattern,
             Y = di.YearMonthPattern,
         }
     };
     var jobj = JObject.FromObject(obj);
     jobj["/"] = di.DateSeparator;
     jobj[":"] = di.TimeSeparator;
     if (!di.MonthNames.SequenceEqual(di.MonthGenitiveNames))
     {
         var monthsGenitive = jobj["monthsGenitive"] = new JObject();
         monthsGenitive["names"] = JArray.FromObject(di.MonthGenitiveNames);
         monthsGenitive["namesAbbr"] = JArray.FromObject(di.AbbreviatedMonthGenitiveNames);
     }
     return new JObject()
     {
         {"standard", jobj }
     };
 }
开发者ID:holajan,项目名称:dotvvm,代码行数:46,代码来源:JQueryGlobalizeScriptCreator.cs

示例5: Format


//.........这里部分代码省略.........
								{
									builder.Append((char)('0' + value));
								}
								else
								{
									builder.Append((char)('0' + (value / 10)));
									builder.Append((char)('0' + (value % 10)));
								}
							}
							else if(count == 2)
							{
								value %= 100;
								builder.Append((char)('0' + (value / 10)));
								builder.Append((char)('0' + (value % 10)));
							}
							else
							{
								builder.Append((char)('0' + (value / 1000)));
								builder.Append
									((char)('0' + ((value / 100 % 10))));
								builder.Append
									((char)('0' + ((value / 10 % 10))));
								builder.Append((char)('0' + (value % 10)));
							}
						}
						break;

						case 'g':
						{
							// Output the era name.
							try
							{
								int era = info.Calendar.GetEra(date);
								builder.Append(info.GetEraName(era));
							}
							catch(ArgumentException)
							{
								// The date does not have an era.
							}
						}
						break;

						case 'h':
						{
							// Output the hour in 12-hour format.
							value = date.Hour;
							if(value == 0)
							{
								value = 12;
							}
							else if(value > 12)
							{
								value -= 12;
							}
							if(count == 1)
							{
								if(value < 10)
								{
									builder.Append((char)('0' + value));
								}
								else
								{
									builder.Append((char)('0' + (value / 10)));
									builder.Append((char)('0' + (value % 10)));
								}
							}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:67,代码来源:DateTimeFormatter.cs

示例6: ClientCultureInfo

 private ClientCultureInfo(CultureInfo cultureInfo) {
     name = cultureInfo.Name;
     numberFormat = cultureInfo.NumberFormat;
     dateTimeFormat = cultureInfo.DateTimeFormat;
     var calendar = dateTimeFormat == null ? null : dateTimeFormat.Calendar;
     if (calendar != null) {
         // Dev10 425049: Support Eras for gregorian based calendars
         // with a simple year offset, and non-gregorian calendars.
         // Era data is stored in binary resource "culture.nlp" in mscorlib,
         // hard coded here for simplicity.
         // era array has the following structure:
         // [eraNumber1, eraName1, eraStartInTicks1, eraGregorianYearOffset1, eraNumber2, ...]
         eras = new object[calendar.Eras.Length * 4];
         int i = 0;
         foreach (int era in calendar.Eras) {
             // era number
             eras[i + eraNumber] = era;
             // era name
             eras[i + eraName] = dateTimeFormat.GetEraName(era);
             // calendars with only one era will have a null tick count
             // signifying that the era starts from the lowest datetime
             // era begining in ticks (null = the oldest era)
             // eras[i + eraStart] = null;
             // era year offset from normal gregorian year
             // some calendars dont have an offset, just a different name
             // for the A.D. era (B.C. is not supported by normal calendar,
             // so most calendars only have 1 era)
             eras[i + eraYearOffset] = 0;
             i += 4;
         }
         var calendarType = calendar.GetType();
         if (calendarType != typeof(GregorianCalendar)) {
             if (calendarType == typeof(TaiwanCalendar)) {
                 // Only the current era is supported, so no tick count is needed
                 //eras[eraStart] = -1830384000000;
                 eras[eraYearOffset] = 1911;
             }
             else if (calendarType == typeof(KoreanCalendar)) {
                 // only one era to speak of, so no tick count is needed
                 //eras[eraStart] = -62135596800000;
                 eras[eraYearOffset] = -2333;
             }
             else if (calendarType == typeof(ThaiBuddhistCalendar)) {
                 // only one era to speak of, so no tick count is needed
                 //eras[eraStart] = -62135596800000;
                 eras[eraYearOffset] = -543;
             }
             else if (calendarType == typeof(JapaneseCalendar)) {
                 // there are multiple eras
                 eras[0 + eraStart] = 60022080000;
                 eras[0 + eraYearOffset] = 1988;
                 eras[4 + eraStart] = -1357603200000;
                 eras[4 + eraYearOffset] = 1925;
                 eras[8 + eraStart] = -1812153600000;
                 eras[8 + eraYearOffset] = 1911;
                 // oldest era is technically from this offset, but for simplicity
                 // it is counted from the lowest date time, so no tick count needed.
                 //eras[12 + eraStart] = -3218832000000;
                 eras[12 + eraYearOffset] = 1867;
             }
             else if (calendarType == typeof(HijriCalendar)) {
                 _convertScript = "Date.HijriCalendar.js";
                 _adjustment = ((HijriCalendar)calendar).HijriAdjustment;
             }
             else if (calendarType == typeof(UmAlQuraCalendar)) {
                 _convertScript = "Date.UmAlQuraCalendar.js";
             }
             // else { other calendars arent supported or have no era offsets just different names for A.D.
         }
     }
     
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:72,代码来源:ClientCultureInfo.cs

示例7: VerificationHelper

 private void VerificationHelper(DateTimeFormatInfo info, int era, string expected)
 {
     string actual = info.GetEraName(era);
     Assert.Equal(expected, actual);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:5,代码来源:DateTimeFormatInfoGetEraName.cs

示例8: ToString


//.........这里部分代码省略.........
						if (offset.Ticks >= 0)
							result.Append ('+');
						else
							result.Append ('-');
						result.Append (Math.Abs (offset.Hours).ToString ("00"));
						result.Append (':');
						result.Append (Math.Abs (offset.Minutes).ToString ("00"));
					} else if (dt.Kind == DateTimeKind.Utc)
						result.Append ('Z');
					break;
				//
				// Date tokens
				//
				case 'd':
					// day. d(d?) = day of month (leading 0 if two d's)
					// ddd = three leter day of week
					// dddd+ full day-of-week
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);

					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)));

					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
						result.Append (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 = DateTimeUtils.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 ();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:DateTimeUtils.cs

示例9: FormatCustomized


//.........这里部分代码省略.........
                            goto Label_03C7;
                        }
                        HebrewFormatDigits(outputBuffer, month);
                        goto Label_042E;

                    case '\\':
                    {
                        num4 = ParseNextChar(format, i);
                        if (num4 < 0)
                        {
                            throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                        }
                        outputBuffer.Append((char) num4);
                        num2 = 2;
                        continue;
                    }
                    case 'd':
                        num2 = ParseRepeatPattern(format, i, patternChar);
                        if (num2 > 2)
                        {
                            goto Label_037F;
                        }
                        dayOfMonth = calendar.GetDayOfMonth(dateTime);
                        if (!flag)
                        {
                            goto Label_0373;
                        }
                        HebrewFormatDigits(outputBuffer, dayOfMonth);
                        goto Label_0399;

                    case 'g':
                    {
                        num2 = ParseRepeatPattern(format, i, patternChar);
                        outputBuffer.Append(dtfi.GetEraName(calendar.GetEra(dateTime)));
                        continue;
                    }
                    case 'h':
                    {
                        num2 = ParseRepeatPattern(format, i, patternChar);
                        int num3 = dateTime.Hour % 12;
                        if (num3 == 0)
                        {
                            num3 = 12;
                        }
                        FormatDigits(outputBuffer, num3, num2);
                        continue;
                    }
                    case 's':
                    {
                        num2 = ParseRepeatPattern(format, i, patternChar);
                        FormatDigits(outputBuffer, dateTime.Second, num2);
                        continue;
                    }
                    case 't':
                    {
                        num2 = ParseRepeatPattern(format, i, patternChar);
                        if (num2 != 1)
                        {
                            goto Label_0327;
                        }
                        if (dateTime.Hour >= 12)
                        {
                            goto Label_02FE;
                        }
                        if (dtfi.AMDesignator.Length >= 1)
                        {
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:67,代码来源:DateTimeFormat.cs

示例10: GetEraName

 public void GetEraName(DateTimeFormatInfo format, int era, string expected)
 {
     Assert.Equal(expected, format.GetEraName(era));
 }
开发者ID:benpye,项目名称:corefx,代码行数:4,代码来源:DateTimeFormatInfoGetEraName.cs

示例11: FormatCustomized


//.........这里部分代码省略.........
										{
											num2 = DateTimeFormat.ParseRepeatPattern(format, i, c);
											if (num2 <= 2)
											{
												int dayOfMonth = calendar.GetDayOfMonth(dateTime);
												if (flag)
												{
													DateTimeFormat.HebrewFormatDigits(stringBuilder, dayOfMonth);
												}
												else
												{
													DateTimeFormat.FormatDigits(stringBuilder, dayOfMonth, num2);
												}
											}
											else
											{
												int dayOfWeek = (int)calendar.GetDayOfWeek(dateTime);
												stringBuilder.Append(DateTimeFormat.FormatDayOfWeek(dayOfWeek, num2, dtfi));
											}
											timeOnly = false;
											break;
										}
										case 'e':
										{
											goto IL_5A4;
										}
										case 'f':
										{
											goto IL_1BA;
										}
										case 'g':
										{
											num2 = DateTimeFormat.ParseRepeatPattern(format, i, c);
											stringBuilder.Append(dtfi.GetEraName(calendar.GetEra(dateTime)));
											break;
										}
										case 'h':
										{
											num2 = DateTimeFormat.ParseRepeatPattern(format, i, c);
											int num3 = dateTime.Hour % 12;
											if (num3 == 0)
											{
												num3 = 12;
											}
											DateTimeFormat.FormatDigits(stringBuilder, num3, num2);
											break;
										}
										default:
										{
											goto IL_5A4;
										}
									}
								}
								else
								{
									int num = DateTimeFormat.ParseNextChar(format, i);
									if (num < 0)
									{
										throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
									}
									stringBuilder.Append((char)num);
									num2 = 2;
								}
								break;
							}
						}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:67,代码来源:DateTimeFormat.cs

示例12: ParseEra

	// Parse an era name.
	private static int ParseEra(String s, ref int posn,
								Calendar calendar, DateTimeFormatInfo info)
			{
				// Get the list of eras from the calendar.
				int[] eras = calendar.Eras;

				// Convert the eras into era names.
				String[] eraNames = new String [eras.Length];
				int index;
				for(index = 0; index < eras.Length; ++index)
				{
					eraNames[index] = info.GetEraName(eras[index]);
				}

				// Parse the era value using the strings we just got.
				return ParseOneOf(s, ref posn, eraNames);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:18,代码来源:DateTimeParser.cs

示例13: FormatCustomized

        //
        //  FormatCustomized
        //
        //  Actions: Format the DateTime instance using the specified format.
        // 
        private static String FormatCustomized(DateTime dateTime, String format, DateTimeFormatInfo dtfi) {
            Calendar cal = dtfi.Calendar;
            StringBuilder result = new StringBuilder();
            // This is a flag to indicate if we are format the dates using Hebrew calendar.

            bool isHebrewCalendar = (cal.ID == Calendar.CAL_HEBREW);
            // This is a flag to indicate if we are formating hour/minute/second only.
            bool bTimeOnly = true;
                        
            int i = 0;
            int tokenLen, hour12;
            
            while (i < format.Length) {
                char ch = format[i];
                int nextChar;
                switch (ch) {
                    case 'g':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        result.Append(dtfi.GetEraName(cal.GetEra(dateTime)));
                        break;
                    case 'h':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        hour12 = dateTime.Hour % 12;
                        if (hour12 == 0)
                        {
                            hour12 = 12;
                        }
                        FormatDigits(result, hour12, tokenLen);
                        break;
                    case 'H':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Hour, tokenLen);
                        break;
                    case 'm':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Minute, tokenLen);
                        break;
                    case 's':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Second, tokenLen);
                        break;
                    case 'f':
                    case 'F':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        if (tokenLen <= MaxSecondsFractionDigits) {
                            long fraction = (dateTime.Ticks % Calendar.TicksPerSecond);
                            fraction = fraction / (long)Math.Pow(10, 7 - tokenLen);
                            if (ch == 'f') {
                                result.Append(((int)fraction).ToString(fixedNumberFormats[tokenLen - 1], CultureInfo.InvariantCulture));
                            }
                            else {
                                int effectiveDigits = tokenLen;
                                while (effectiveDigits > 0) {
                                    if (fraction % 10 == 0) {
                                        fraction = fraction / 10;
                                        effectiveDigits--;
                                    }
                                    else {
                                        break;
                                    }
                                }
                                if (effectiveDigits > 0) {
                                    result.Append(((int)fraction).ToString(fixedNumberFormats[effectiveDigits - 1], CultureInfo.InvariantCulture));
                                }
                                else {
                                    // No fraction to emit, so see if we should remove decimal also.
                                    if (result.Length > 0 && result[result.Length - 1] == '.') {
                                        result.Remove(result.Length - 1, 1);
                                    }
                                }
                            }
                        } else {
                            throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                        }
                        break;
                    case 't':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        if (tokenLen == 1)
                        {
                            if (dateTime.Hour < 12)
                            {
                                if (dtfi.AMDesignator.Length >= 1)
                                {
                                    result.Append(dtfi.AMDesignator[0]);
                                }
                            }
                            else
                            {
                                if (dtfi.PMDesignator.Length >= 1)
                                {
                                    result.Append(dtfi.PMDesignator[0]);
                                }
                            }
                            
                        }
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:datetimeformat.cs

示例14: MatchEraName

        /*=================================MatchEraName==================================
        **Action: Parse era name from string starting at str.Index.
        **Returns: An era value. 
        **Arguments:    str: a __DTString.  The parsing will start from the
        **              next character after str.Index.
        **Exceptions: FormatException if an era name can not be found.
        ==============================================================================*/

        private static bool MatchEraName(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
            if (str.GetNext()) {
                int[] eras = dtfi.Calendar.Eras;

                if (eras != null) {
                    for (int i = 0; i <= eras.Length; i++) {
                        String searchStr = dtfi.GetEraName(eras[i]);
                        if (str.MatchSpecifiedWord(searchStr)) {
                            str.Index += (searchStr.Length - 1);
                            result = eras[i];
                            return (true);
                        }
                        searchStr = dtfi.GetAbbreviatedEraName(eras[i]);
                        if (str.MatchSpecifiedWord(searchStr)) {
                            str.Index += (searchStr.Length - 1);
                            result = eras[i];
                            return (true);
                        }
                    }
                }
            }
            return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
        }
开发者ID:ArildF,项目名称:masters,代码行数:31,代码来源:datetimeparse.cs

示例15: FormatCustomized

        private static String FormatCustomized(DateTime dateTime, String format, DateTimeFormatInfo dtfi) {
            Calendar cal = dtfi.Calendar;
            StringBuilder result = new StringBuilder();
            // This is a flag to indicate if we are format the dates using Hebrew calendar.

            bool isHebrewCalendar = (cal.ID == Calendar.CAL_HEBREW);
            // This is a flag to indicate if we are formating hour/minute/second only.
            bool bTimeOnly = true;
                        
            int i = 0;
            int tokenLen, hour12;
            
            while (i < format.Length) {
                char ch = format[i];
                int nextChar;
                switch (ch) {
                    case 'g':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        result.Append(dtfi.GetEraName(cal.GetEra(dateTime)));
                        break;
                    case 'h':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        hour12 = dateTime.Hour % 12;
                        if (hour12 == 0)
                        {
                            hour12 = 12;
                        }
                        FormatDigits(result, hour12, tokenLen);
                        break;
                    case 'H':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Hour, tokenLen);
                        break;
                    case 'm':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Minute, tokenLen);
                        break;
                    case 's':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        FormatDigits(result, dateTime.Second, tokenLen);
                        break;
                    case 'f':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        if (tokenLen <= MaxSecondsFractionDigits) {
                            long fraction = (dateTime.Ticks % Calendar.TicksPerSecond);
                            fraction = fraction / (long)Math.Pow(10, 7 - tokenLen);
                            result.Append(((int)fraction).ToString((new String('0', tokenLen))));
                        } else {
                            throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                        }
                        break;
                    case 't':
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        if (tokenLen == 1)
                        {
                            if (dateTime.Hour < 12)
                            {
                                if (dtfi.AMDesignator.Length >= 1)
                                {
                                    result.Append(dtfi.AMDesignator[0]);
                                }
                            }
                            else
                            {
                                if (dtfi.PMDesignator.Length >= 1)
                                {
                                    result.Append(dtfi.PMDesignator[0]);
                                }
                            }
                            
                        }
                        else
                        {
                            result.Append((dateTime.Hour < 12 ? dtfi.AMDesignator : dtfi.PMDesignator));
                        }
                        break;
                    case 'd':
                        //
                        // tokenLen == 1 : Day of month as digits with no leading zero.
                        // tokenLen == 2 : Day of month as digits with leading zero for single-digit months.
                        // tokenLen == 3 : Day of week as a three-leter abbreviation.
                        // tokenLen >= 4 : Day of week as its full name.
                        //
                        tokenLen = ParseRepeatPattern(format, i, ch);
                        if (tokenLen <= 2)
                        {
                            int day = cal.GetDayOfMonth(dateTime);
                            if (isHebrewCalendar) {
                                // For Hebrew calendar, we need to convert numbers to Hebrew text for yyyy, MM, and dd values.
                                HebrewFormatDigits(result, day);
                            } else {
                                FormatDigits(result, day, tokenLen);
                            }
                        } 
                        else
                        {
                            int dayOfWeek = (int)cal.GetDayOfWeek(dateTime);
                            result.Append(FormatDayOfWeek(dayOfWeek, tokenLen, dtfi));
                        }
                        bTimeOnly = false;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:datetimeformat.cs


注:本文中的System.Globalization.DateTimeFormatInfo.GetEraName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。