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


C# Calendar.ToDateTime方法代码示例

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


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

示例1: AssertEquivalent

        /// <summary>
        /// Checks that each day from the given start year to the end year (inclusive) is equal
        /// between the BCL and the Noda Time calendar. Additionally, the number of days in each month and year
        /// and the number of months (and leap year status) in each year is checked.
        /// </summary>
        internal static void AssertEquivalent(Calendar bcl, CalendarSystem noda, int fromYear, int toYear)
        {
            // We avoid asking the BCL to create a DateTime on each iteration, simply
            // because the BCL implementation is so slow. Instead, we just check at the start of each month that
            // we're at the date we expect.
            DateTime bclDate = bcl.ToDateTime(fromYear, 1, 1, 0, 0, 0, 0);
            for (int year = fromYear; year <= toYear; year++)
            {
                Assert.AreEqual(bcl.GetDaysInYear(year), noda.GetDaysInYear(year), "Year: {0}", year);
                Assert.AreEqual(bcl.GetMonthsInYear(year), noda.GetMonthsInYear(year), "Year: {0}", year);
                for (int month = 1; month <= noda.GetMonthsInYear(year); month++)
                {
                    // Sanity check at the start of each month. Even this is surprisingly slow.
                    // (These three tests make up about 20% of the total execution time for the test.)
                    Assert.AreEqual(year, bcl.GetYear(bclDate));
                    Assert.AreEqual(month, bcl.GetMonth(bclDate));
                    Assert.AreEqual(1, bcl.GetDayOfMonth(bclDate));

                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                        "Year: {0}; Month: {1}", year, month);
                    Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year), "Year: {0}", year);
                    for (int day = 1; day <= noda.GetDaysInMonth(year, month); day++)
                    {
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.ToDateTimeUnspecified(),
                            "Original calendar system date: {0:yyyy-MM-dd}", nodaDate);
                        Assert.AreEqual(nodaDate, LocalDate.FromDateTime(bclDate, noda));
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                        bclDate = bclDate.AddDays(1);
                    }
                }
            }
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:40,代码来源:BclEquivalenceHelper.cs

示例2: ExecutePosTest

 private void ExecutePosTest(Calendar myCalendar, int year, int month, int day, int hour, int minute,
     int second, int millisecond, int era)
 {
     DateTime actualTime, expectedTime;
     expectedTime = new DateTime(year, month, day, hour, minute, second, millisecond);
     actualTime = myCalendar.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
     Assert.Equal(expectedTime, actualTime);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:GregorianCalendarToDateTime.cs

示例3: IsRepresentable

        public static bool IsRepresentable( this DateTime date, Calendar calendar, int year, int month, int day )
        {
            Arg.NotNull( calendar, nameof( calendar ) );

            if ( date < calendar.MinSupportedDateTime || date > calendar.MaxSupportedDateTime )
                return false;

            try
            {
                calendar.ToDateTime( year, month, day, date.Hour, date.Minute, date.Second, date.Millisecond );
            }
            catch ( ArgumentOutOfRangeException )
            {
                return false;
            }

            return true;
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:18,代码来源:DateTimeExtensions.cs

示例4: ExecutePosTest

 private void ExecutePosTest(string errorNum1, string errorNum2, Calendar myCalendar, int year,
     int month, int day, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     DateTime time;
     int actualDayOfYear, expectedDayOfYear;
     int weekOfYear;
     time = myCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
     expectedDayOfYear = myCalendar.GetDayOfYear(time);
     weekOfYear = myCalendar.GetWeekOfYear(time, rule, firstDayOfWeek);
     actualDayOfYear = this.GetDayOfYear(time, rule, firstDayOfWeek, weekOfYear, myCalendar);
     Assert.Equal(expectedDayOfYear, actualDayOfYear);
 }
开发者ID:kkurni,项目名称:corefx,代码行数:12,代码来源:GregorianCalendarGetWeekOfYears.cs

示例5: ExecuteAOORETest

 private void ExecuteAOORETest(Calendar myCalendar, int year, int month, int day, int hour, int minute,
     int second, int millisecond, int era)
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         myCalendar.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
     });
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:GregorianCalendarToDateTime.cs

示例6: ToDateTime

	public DateTime ToDateTime(Calendar cal) {
		return cal.ToDateTime(Year,Month,Day,0,0,0,0,Era);
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:3,代码来源:CalendarTest.cs

示例7: DateTime

	public DateTime(int year, int month, int day,
					int hour, int minute, int second, int millisecond,
				    Calendar calendar)
			{
				if(calendar == null)
				{
					throw new ArgumentNullException("calendar");
				}
				value_ = calendar.ToDateTime(year, month, day, hour,
											  minute, second, millisecond,
											  Calendar.CurrentEra)
								.Ticks;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:13,代码来源:DateTime.cs

示例8: DateTime

 // Constructs a DateTime from a given year, month, day, hour,
 // minute, and second for the specified calendar.
 //
 /// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime6"]/*' />
 public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar) {
     if (calendar == null)
         throw new ArgumentNullException("calendar");
     ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
     if (millisecond < 0 || millisecond >= MillisPerSecond) {
         throw new ArgumentOutOfRangeException("millisecond", String.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), 0, MillisPerSecond - 1));
     }            
     ticks += millisecond * TicksPerMillisecond;
     if (ticks < MinTicks || ticks > MaxTicks)
         throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
 }
开发者ID:ArildF,项目名称:masters,代码行数:15,代码来源:datetime.cs

示例9: StartOfMonth

        public static DateTime StartOfMonth( this DateTime date, Calendar calendar )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( calendar.GetMonth( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetMonth( date ) ) );

            var year = calendar.GetYear( date );
            var month = calendar.GetMonth( date );
            return calendar.ToDateTime( year, month, 1, date.Hour, date.Minute, date.Second, date.Millisecond );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:10,代码来源:DateTimeExtensions.cs

示例10: GetStartDate

 private DateTime GetStartDate(Calendar calendar)
   {
   Int32 year = calendar.TwoDigitYearMax-90;		
   DateTime date = calendar.ToDateTime(year, 1, 1, 1, 1, 1, 980);
   return date;
   }    
开发者ID:ArildF,项目名称:masters,代码行数:6,代码来源:co8571parse_ifp_dts.cs


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