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


C# DateTimeFormatInfo.GetAbbreviatedDayName方法代码示例

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


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

示例1: GetForecastAsync

		public async Task<Forecast> GetForecastAsync (Position location)
		{
			var openWeatherForecast = await _openWeatherMapService.Get7DayForecastAsync (location);
			var forecast = new Forecast () {
				Location = location
			};

			var daysClean = 0;
			var dtf = new DateTimeFormatInfo ();
			
			foreach (var forecastItem in openWeatherForecast.Forecasts) {
				var weather = forecastItem.WeatherList.FirstOrDefault ();
				var date = new DateTime (1970, 1, 1).AddSeconds (forecastItem.Dt);
			
				forecast.WeatherList.Add (new WeatherViewTemplate {
					WeatherCondition = weather.Description,
					DayAbbreviation = dtf.GetAbbreviatedDayName (date.DayOfWeek),
					TempHigh = Convert.ToInt32(forecastItem.Temperature.Max) + "º",
					TempLow = Convert.ToInt32(forecastItem.Temperature.Min) + "º",
					Icon = GetWeatherIcon (weather.Main)
				});
			
			}

			foreach (var forecastItem in openWeatherForecast.Forecasts) {
				var date = new DateTime (1970, 1, 1).AddSeconds (forecastItem.Dt);
			
				if (date.Date.Date < DateTime.Now.Date.Date)
					continue;
			
				var weatherForToday = forecastItem.WeatherList [0];
			
				forecast.BadWeatherDay = date;
				forecast.Reason = ConvertReason (weatherForToday.Main);
				forecast.ReasonDescription = weatherForToday.Description;
			
				if (WeatherIsBad (weatherForToday))
					break;
			
				daysClean++;
			}
			
			forecast.DaysClean = daysClean;

			return forecast;
		}
开发者ID:vmoll,项目名称:ShouldIWashMyCar,代码行数:46,代码来源:ForecastService.cs

示例2: NegTest1

 public void NegTest1()
 {
     DateTimeFormatInfo info = new DateTimeFormatInfo();
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         info.GetAbbreviatedDayName((DayOfWeek)(-1));
     });
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:8,代码来源:DateTimeFormatInfoGetDayName.cs

示例3: MatchAbbreviatedDayName

		private static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
		{
			int num = 0;
			result = -1;
			if (str.GetNext())
			{
				for (DayOfWeek dayOfWeek = DayOfWeek.Sunday; dayOfWeek <= DayOfWeek.Saturday; dayOfWeek += DayOfWeek.Monday)
				{
					string abbreviatedDayName = dtfi.GetAbbreviatedDayName(dayOfWeek);
					int length = abbreviatedDayName.Length;
					if ((dtfi.HasSpacesInDayNames ? str.MatchSpecifiedWords(abbreviatedDayName, false, ref length) : str.MatchSpecifiedWord(abbreviatedDayName)) && length > num)
					{
						num = length;
						result = (int)dayOfWeek;
					}
				}
			}
			if (result >= 0)
			{
				str.Index += num - 1;
				return true;
			}
			return false;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:24,代码来源:DateTimeParse.cs

示例4: MatchAbbreviatedDayName

        /*=================================MatchAbbreviatedDayName==================================
        **Action: Parse the abbreviated day of week name from string starting at str.Index.
        **Returns: A value from 0 to 6 indicating Sunday to Saturday.
        **Arguments:    str: a __DTString.  The parsing will start from the
        **              next character after str.Index.
        **Exceptions: FormatException if a abbreviated day of week name can not be found.
        ==============================================================================*/

        private static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) {
            int maxMatchStrLen = 0;
            result = -1;
            if (str.GetNext()) {
                for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
                    String searchStr = dtfi.GetAbbreviatedDayName(i);
                    int matchStrLen = searchStr.Length;
                    if ( dtfi.HasSpacesInDayNames
                            ? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
                            : str.MatchSpecifiedWord(searchStr)) {
                        if (matchStrLen > maxMatchStrLen) {
                            maxMatchStrLen = matchStrLen;
                            result = (int)i;
                        }
                    }
                }
            }
            if (result >= 0) {
                str.Index += maxMatchStrLen - 1;
                return (true);
            }
            return false;
        }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:31,代码来源:DateTimeParse.cs

示例5: FormatDayOfWeek

 private static String FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
 {
     Contract.Assert(dayOfWeek >= 0 && dayOfWeek <= 6, "dayOfWeek >= 0 && dayOfWeek <= 6");
     if (repeat == 3)
     {            
         return (dtfi.GetAbbreviatedDayName((DayOfWeek)dayOfWeek));
     }
     // Call dtfi.GetDayName() here, instead of accessing DayNames property, because we don't
     // want a clone of DayNames, which will hurt perf.
     return (dtfi.GetDayName((DayOfWeek)dayOfWeek));
 }
开发者ID:afrog33k,项目名称:csnative,代码行数:11,代码来源:DateTimeFormat.cs

示例6: GetDayName

        /// <summary>
        /// Gets the abbreviated or full day name for the specified <see cref="DayOfWeek"/> value using, if not null, the <paramref name="nameProvider"/> or
        /// the <see cref="DateTimeFormatInfo"/> specified by <paramref name="info"/>.
        /// </summary>
        /// <param name="dayofweek">
        /// The <see cref="DayOfWeek"/> value to get the day name for.
        /// </param>
        /// <param name="info">
        /// The <see cref="DateTimeFormatInfo"/> to get the name.
        /// </param>
        /// <param name="nameProvider">
        /// The <see cref="ICustomFormatProvider"/> to get the name. This parameter has precedence before the
        /// <paramref name="info"/>. Can be <c>null</c>.
        /// </param>
        /// <param name="abbreviated">
        /// true to get the abbreviated day name; false otherwise.
        /// </param>
        /// <returns>
        /// The full or abbreviated day name specified by <paramref name="dayofweek"/> value.
        /// </returns>
        private static string GetDayName(DayOfWeek dayofweek, DateTimeFormatInfo info, ICustomFormatProvider nameProvider, bool abbreviated)
        {
            if (nameProvider != null)
            {
                return abbreviated ? nameProvider.GetAbbreviatedDayName(dayofweek) : nameProvider.GetDayName(dayofweek);
            }

            return abbreviated ? info.GetAbbreviatedDayName(dayofweek) : info.GetDayName(dayofweek);
        }
开发者ID:tu-tran,项目名称:FareLiz,代码行数:29,代码来源:MonthCalendarDate.cs

示例7: ToString


//.........这里部分代码省略.........
						result.Append (Math.Abs (offset.Hours).ToString ("00"));
						result.Append (':');
						result.Append (Math.Abs (offset.Minutes).ToString ("00"));
						break;
					}
					break;
				case 'K': // 'Z' (UTC) or zzz (Local)
					tokLen = 1;

					if (utc_offset != null || dt.Kind == DateTimeKind.Local) {
						offset = utc_offset ?? TimeZone.CurrentTimeZone.GetUtcOffset (dt);
						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);
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:67,代码来源:DateTimeUtils.cs

示例8: FormatDayOfWeek

 private static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
 {
     if (repeat == 3)
     {
         return dtfi.GetAbbreviatedDayName((DayOfWeek) dayOfWeek);
     }
     return dtfi.GetDayName((DayOfWeek) dayOfWeek);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:DateTimeFormat.cs

示例9: VerificationHelper

        private void VerificationHelper(DateTimeFormatInfo info, string[] expected)
        {
            DayOfWeek[] values = new DayOfWeek[] {
            DayOfWeek.Sunday,
            DayOfWeek.Monday,
            DayOfWeek.Tuesday,
            DayOfWeek.Wednesday,
            DayOfWeek.Thursday,
            DayOfWeek.Friday,
            DayOfWeek.Saturday
            };

            for (int i = 0; i < values.Length; ++i)
            {
                string actual = info.GetAbbreviatedDayName(values[i]);
                Assert.Equal(expected[i], actual);
            }
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:18,代码来源:DateTimeFormatInfoGetAbbreviatedDayName.cs

示例10: GetDayOfWeekNumber

        //
        // Check the word at the current index to see if it matches a day of week name.
        // Return -1 if a match is not found.  Otherwise, a value from 0 to 6 is returned.
        //
        private static int GetDayOfWeekNumber(__DTString str, DateTimeFormatInfo dtfi) {
            //
            // Check the month name specified in dtfi.
            //

            DayOfWeek i;
            
            int maxLen = 0;
            int result = -1;
            //
            // We have to match the day name with the longest length, 
            // since there are cultures which have more than one day of week names
            // with the same prefix.
            //
            int endIndex = str.FindEndOfCurrentWord();
            String dayName=null;
            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
                dayName = dtfi.GetDayName(i);
                if (str.MatchSpecifiedWord(dayName, endIndex)) {
                    if (dayName.Length > maxLen) {
                        result = (int)i;
                        maxLen = dayName.Length;
                    }
                }
                }

            if (result > -1) {
                str.Index = endIndex;
                return (result);
            }

            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
            {
                if (MatchWord(str, dtfi.GetAbbreviatedDayName(i), false))
                {
                    return ((int)i);
                }
            }

            //
            // Check the month name in the invariant culture.
            //
            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
            {
                if (MatchWord(str, invariantInfo.GetDayName(i), false))
                {
                    return ((int)i);
                }
            }

            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
            {
                if (MatchWord(str, invariantInfo.GetAbbreviatedDayName(i), false))
                {
                    return ((int)i);
                }
            }

            return (-1);
        }
开发者ID:ArildF,项目名称:masters,代码行数:64,代码来源:datetimeparse.cs

示例11: MatchAbbreviatedDayName

        /*=================================MatchAbbreviatedDayName==================================
        **Action: Parse the abbreviated day of week name from string starting at str.Index.
        **Returns: A value from 0 to 6 indicating Sunday to Saturday.
        **Arguments:    str: a __DTString.  The parsing will start from the
        **              next character after str.Index.
        **Exceptions: FormatException if a abbreviated day of week name can not be found.
        ==============================================================================*/

        private static bool MatchAbbreviatedDayName(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
            if (str.GetNext()) {
                for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
                    String searchStr = dtfi.GetAbbreviatedDayName(i);
                    if (str.MatchSpecifiedWord(searchStr)) {
                        str.Index += (searchStr.Length - 1);
                        result = (int)i;
                        return (true);
                    }
                }
            }
            return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
        }
开发者ID:ArildF,项目名称:masters,代码行数:21,代码来源:datetimeparse.cs


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