本文整理汇总了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);
}
}
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
});
}
示例6: ToDateTime
public DateTime ToDateTime(Calendar cal) {
return cal.ToDateTime(Year,Month,Day,0,0,0,0,Era);
}
示例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;
}
示例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"));
}
示例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 );
}
示例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;
}