Calendar.ToDateTime 方法

定义

当在派生类中重写时,返回设置为指定日期和时间的 DateTimeWhen overridden in a derived class, returns a DateTime that is set to the specified date and time.

重载

ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

返回设置为当前纪元中指定日期和时间的 DateTimeReturns a DateTime that is set to the specified date and time in the current era.

ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

当在派生类中重写时,将返回设置为指定纪元中指定日期和时间的 DateTimeWhen overridden in a derived class, returns a DateTime that is set to the specified date and time in the specified era.

ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

返回设置为当前纪元中指定日期和时间的 DateTimeReturns a DateTime that is set to the specified date and time in the current era.

public:
 virtual DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond);
public virtual DateTime ToDateTime (int year, int month, int day, int hour, int minute, int second, int millisecond);
abstract member ToDateTime : int * int * int * int * int * int * int -> DateTime
override this.ToDateTime : int * int * int * int * int * int * int -> DateTime
Public Overridable Function ToDateTime (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer) As DateTime

参数

year
Int32

一个整数,用于表示年份。An integer that represents the year.

month
Int32

一个正整数,用于表示月份。A positive integer that represents the month.

day
Int32

一个正整数,用于表示天。A positive integer that represents the day.

hour
Int32

0 到 23 之间的一个整数,用于表示小时。An integer from 0 to 23 that represents the hour.

minute
Int32

0 到 59 之间的一个整数,用于表示分钟。An integer from 0 to 59 that represents the minute.

second
Int32

0 到 59 之间的一个整数,用于表示秒。An integer from 0 to 59 that represents the second.

millisecond
Int32

0 到 999 之间的一个整数,用于表示毫秒。An integer from 0 to 999 that represents the millisecond.

返回

设置为当前纪元中指定日期和时间的 DateTimeThe DateTime that is set to the specified date and time in the current era.

异常

year 超出了日历支持的范围。year is outside the range supported by the calendar.

-or- month 超出了日历支持的范围。month is outside the range supported by the calendar.

- 或 --or- day 超出了日历支持的范围。day is outside the range supported by the calendar.

-or- hour 小于 0 或大于 23。hour is less than zero or greater than 23.

-or- minute 小于 0 或大于 59。minute is less than zero or greater than 59.

- 或 --or- second 小于 0 或大于 59。second is less than zero or greater than 59.

-or- millisecond 小于 0 或大于 999。millisecond is less than zero or greater than 999.

注解

此方法基于特定日历的当前纪元返回日期和时间。This method returns a date and time based on the current era of a particular calendar. JapaneseCalendar对于和JapaneseLunisolarCalendar(基于高层的 reign 支持多个纪元), 调用此方法可能会在纪元发生更改时产生意外日期。For the JapaneseCalendar and JapaneseLunisolarCalendar, which support multiple eras based on the reign of the emperor, calling this method can produce an unintended date when an era changes. 使用其中任一日历来实例化日期时, 建议调用JapaneseCalendar.ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)JapaneseLunisolarCalendar. system.xml.xmlconvert.todatetime (int32、int32、int32、int32、int32、int32、int32、int32)方法并显式指定纪元。When instantiating a date using either of these calendars, we recommend that you call the JapaneseCalendar.ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32) or JapaneseLunisolarCalendar.ToDateTime(Int32,Int32,Int32,Int32,Int32,Int32,Int32,Int32) method and explicitly specify an era.

另请参阅

ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

当在派生类中重写时,将返回设置为指定纪元中指定日期和时间的 DateTimeWhen overridden in a derived class, returns a DateTime that is set to the specified date and time in the specified era.

public:
 abstract DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era);
public abstract DateTime ToDateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, int era);
abstract member ToDateTime : int * int * int * int * int * int * int * int -> DateTime
Public MustOverride Function ToDateTime (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, era As Integer) As DateTime

参数

year
Int32

一个整数,用于表示年份。An integer that represents the year.

month
Int32

一个正整数,用于表示月份。A positive integer that represents the month.

day
Int32

一个正整数,用于表示天。A positive integer that represents the day.

hour
Int32

0 到 23 之间的一个整数,用于表示小时。An integer from 0 to 23 that represents the hour.

minute
Int32

0 到 59 之间的一个整数,用于表示分钟。An integer from 0 to 59 that represents the minute.

second
Int32

0 到 59 之间的一个整数,用于表示秒。An integer from 0 to 59 that represents the second.

millisecond
Int32

0 到 999 之间的一个整数,用于表示毫秒。An integer from 0 to 999 that represents the millisecond.

era
Int32

一个整数,用于表示纪元。An integer that represents the era.

返回

设置为当前纪元中指定日期和时间的 DateTimeThe DateTime that is set to the specified date and time in the current era.

异常

year 超出了日历支持的范围。year is outside the range supported by the calendar.

-or- month 超出了日历支持的范围。month is outside the range supported by the calendar.

- 或 --or- day 超出了日历支持的范围。day is outside the range supported by the calendar.

-or- hour 小于 0 或大于 23。hour is less than zero or greater than 23.

- 或 --or- minute 小于 0 或大于 59。minute is less than zero or greater than 59.

- 或 --or- second 小于 0 或大于 59。second is less than zero or greater than 59.

- 或 --or- millisecond 小于 0 或大于 999。millisecond is less than zero or greater than 999.

-or- era 超出了日历支持的范围。era is outside the range supported by the calendar.

注解

ToDateTime方法非常有用, 因为它可以将当前日历中的任何日期转换为公历日期。The ToDateTime method is useful because it can convert any date in the current calendar to a Gregorian calendar date. 以后可以使用公历日期来比较不同日历中的日期或在特定日历中创建等效日期。The Gregorian date can subsequently be used, for example, to compare dates in different calendars or create an equivalent date in a particular calendar.

继承者说明

当派生类era作为参数CurrentEra传递时, 必须支持。The derived class must support CurrentEra when it is passed as the era parameter. 支持CurrentEra的一种方法是将其替换为存储在Eras属性数组的第一个元素中的值, 这是日历当前纪元的值。One way to support CurrentEra is by replacing it with the value stored in the first element of the Eras property array, which is the value for the current era of the calendar.

另请参阅

适用于