DateTimeOffset コンストラクター

定義

DateTimeOffset 構造体の新しいインスタンスを初期化します。

オーバーロード

DateTimeOffset(DateTime)

指定した DateTime 値を使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(DateTime, TimeSpan)

指定した DateTime 値とオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int64, TimeSpan)

指定したティック数とオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(DateOnly, TimeOnly, TimeSpan)

指定した datetime、および offsetを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した年、月、日、時、分、秒、オフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した年、月、日、時、分、秒、ミリ秒、オフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

指定したカレンダーの年、月、日、時、分、秒、ミリ秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した yearmonthdayhourminutesecondmillisecondmicrosecond、および offsetを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

指定した yearmonthdayhourminutesecondmillisecondmicrosecond、および offsetを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(DateTime)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定した DateTime 値を使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(DateTime dateTime);
public DateTimeOffset (DateTime dateTime);
new DateTimeOffset : DateTime -> DateTimeOffset
Public Sub New (dateTime As DateTime)

パラメーター

dateTime
DateTime

日付と時刻。

例外

オフセットの適用結果の協定世界時 (UTC) の日付と時刻は、DateTimeOffset.MinValueよりも前です。

-又は-

オフセットの適用結果の UTC 日時は、DateTimeOffset.MaxValueよりも後です。

次の例は、dateTime パラメーターの DateTime.Kind プロパティの値がこのコンストラクターによって返される日付と時刻の値にどのように影響するかを示しています。

DateTime localNow = DateTime.Now;
DateTimeOffset localOffset = new DateTimeOffset(localNow);
Console.WriteLine(localOffset.ToString());

DateTime utcNow = DateTime.UtcNow;
DateTimeOffset utcOffset = new DateTimeOffset(utcNow);
Console.WriteLine(utcOffset.ToString());

DateTime unspecifiedNow = DateTime.SpecifyKind(DateTime.Now,
                               DateTimeKind.Unspecified);
DateTimeOffset unspecifiedOffset = new DateTimeOffset(unspecifiedNow);
Console.WriteLine(unspecifiedOffset.ToString());
//
// The code produces the following output if run on Feb. 23, 2007, on
// a system 8 hours earlier than UTC:
//   2/23/2007 4:21:58 PM -08:00
//   2/24/2007 12:21:58 AM +00:00
//   2/23/2007 4:21:58 PM -08:00
let localNow = DateTime.Now
let localOffset = DateTimeOffset localNow
printfn $"{localOffset}"

let utcNow = DateTime.UtcNow
let utcOffset = DateTimeOffset utcNow
printfn "{utcOffset}"

let unspecifiedNow = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified)
let unspecifiedOffset = DateTimeOffset unspecifiedNow
printfn $"{unspecifiedOffset}"

// The code produces the following output if run on Feb. 23, 2007, on
// a system 8 hours earlier than UTC:
//   2/23/2007 4:21:58 PM -08:00
//   2/24/2007 12:21:58 AM +00:00
//   2/23/2007 4:21:58 PM -08:00
Dim localNow As Date = Date.Now
Dim localOffset As New DateTimeOffset(localNow)
Console.WriteLine(localOffset.ToString())

Dim utcNow As Date = Date.UtcNow
Dim utcOffset As New DateTimeOffset(utcNow)
Console.WriteLine(utcOffset.ToString())

Dim unspecifiedNow As Date = Date.SpecifyKind(Date.Now, _
                                  DateTimeKind.Unspecified)
Dim unspecifiedOffset As New DateTimeOffset(unspecifiedNow)
Console.WriteLine(unspecifiedOffset.ToString())
'
' The code produces the following output if run on Feb. 23, 2007, on
' a system 8 hours earlier than UTC:
'    2/23/2007 4:21:58 PM -08:00
'    2/24/2007 12:21:58 AM +00:00
'    2/23/2007 4:21:58 PM -08:00

注釈

このコンストラクターの動作は、dateTime パラメーターの DateTime.Kind プロパティの値によって異なります。

こちらもご覧ください

  • DateTimeOffset オブジェクト をインスタンス化する

適用対象

DateTimeOffset(DateTime, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定した DateTime 値とオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(DateTime dateTime, TimeSpan offset);
public DateTimeOffset (DateTime dateTime, TimeSpan offset);
new DateTimeOffset : DateTime * TimeSpan -> DateTimeOffset
Public Sub New (dateTime As DateTime, offset As TimeSpan)

パラメーター

dateTime
DateTime

日付と時刻。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

例外

dateTime.KindUtc に等しく、offset は 0 と等しくありません。

-又は-

dateTime.KindLocal に等しく、offset はシステムのローカル タイム ゾーンのオフセットと等しくありません。

-又は-

offset は、分単位で指定されません。

offset が -14 時間未満か、14 時間を超えています。

-又は-

が DateTimeOffset.MinValue より小さいか、DateTimeOffset.MaxValueより大きい値です。

次の例は、そのタイム ゾーンが事前に不明な場合に、日付と時刻とローカル タイム ゾーンのオフセットを使用して、DateTimeOffset オブジェクトを初期化する方法を示しています。

DateTime localTime = new DateTime(2007, 07, 12, 06, 32, 00);
DateTimeOffset dateAndOffset = new DateTimeOffset(localTime,
                         TimeZoneInfo.Local.GetUtcOffset(localTime));
Console.WriteLine(dateAndOffset);
// The code produces the following output:
//    7/12/2007 6:32:00 AM -07:00
let localTime = DateTime(2007, 07, 12, 06, 32, 00)
let dateAndOffset = DateTimeOffset(localTime, TimeZoneInfo.Local.GetUtcOffset localTime)
printfn $"{dateAndOffset}"
// The code produces the following output:
//    7/12/2007 6:32:00 AM -07:00
Dim localTime As Date = #07/12/2007 6:32AM#
Dim dateAndOffset As New DateTimeOffset(localTime, _
                         TimeZoneInfo.Local.GetUtcOffset(localTime))
Console.WriteLine(dateAndOffset)
' The code produces the following output:
'    7/12/2007 6:32:00 AM -07:00

注釈

このコンストラクターの動作は、dateTime パラメーターの Kind プロパティの値に部分的に依存します。

  • Kind の値が DateTimeKind.Utc場合、offset パラメーターの値は 0 であるか、ArgumentException がスローされます。

  • Kind の値が DateTimeKind.Local場合、offset パラメーターの値は、その特定の日付の世界協定時刻 (UTC) からのローカル タイム ゾーンのオフセットと等しいか、ArgumentException がスローされる必要があります。

  • Kind の値が DateTimeKind.Unspecified場合、offset パラメーターには任意の有効な値を指定できます。

こちらもご覧ください

  • DateTimeOffset オブジェクト をインスタンス化する

適用対象

DateTimeOffset(Int64, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定したティック数とオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(long ticks, TimeSpan offset);
public DateTimeOffset (long ticks, TimeSpan offset);
new DateTimeOffset : int64 * TimeSpan -> DateTimeOffset
Public Sub New (ticks As Long, offset As TimeSpan)

パラメーター

ticks
Int64

0001 年 1 月 1 日の午前 12 時 00 分から経過した 100 ナノ秒間隔の数で表される日時。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

例外

offset は、分単位で指定されません。

プロパティが DateTimeOffset.MinValue より前か、DateTimeOffset.MaxValueより後です。

-又は-

ticksDateTimeOffset.MinValue.Ticks より小さいか、DateTimeOffset.MaxValue.Ticksより大きいです。

-又は-

offset が -14 時間未満か、14 時間を超えています。

次の例では、任意の日付 (この場合は 2007 年 7 月 16 日午後 1 時 32 分) のティック数を使用して、-5 のオフセットを使用して、DateTimeOffset オブジェクトを初期化します。

DateTime dateWithoutOffset = new DateTime(2007, 7, 16, 13, 32, 00);
DateTimeOffset timeFromTicks = new DateTimeOffset(dateWithoutOffset.Ticks,
                               new TimeSpan(-5, 0, 0));
Console.WriteLine(timeFromTicks.ToString());
// The code produces the following output:
//    7/16/2007 1:32:00 PM -05:00
let dateWithoutOffset = DateTime(2007, 7, 16, 13, 32, 00)
let timeFromTicks = DateTimeOffset(dateWithoutOffset.Ticks, TimeSpan(-5, 0, 0))
printfn $"{timeFromTicks}"
// The code produces the following output:
//    7/16/2007 1:32:00 PM -05:00
Dim dateWithoutOffset As Date = #07/16/2007 1:32PM#
Dim timeFromTicks As New DateTimeOffset(datewithoutOffset.Ticks, _
                         New TimeSpan(-5, 0, 0))
Console.WriteLine(timeFromTicks.ToString())
' The code produces the following output:
'    7/16/2007 1:32:00 PM -05:00

注釈

通常、DateTimeOffset コンストラクターを呼び出して、ローカル時刻とローカル タイム ゾーン以外のオフセットを使用して DateTimeOffset 値をインスタンス化しようとすると、ArgumentExceptionがスローされます。 この制限を回避するには、DateTimeOffset コンストラクターのこのオーバーロードを使用できます。 次の例では、ローカル時刻のティック数を使用して、オフセットが必ずしもローカル時刻の値を表すわけではない DateTimeOffset 値をインスタンス化します。

DateTime localTime = DateTime.Now;
DateTimeOffset nonLocalDateWithOffset = new DateTimeOffset(localTime.Ticks,
                                  new TimeSpan(2, 0, 0));
Console.WriteLine(nonLocalDateWithOffset);
//
// The code produces the following output if run on Feb. 23, 2007:
//    2/23/2007 4:37:50 PM +02:00
let localTime = DateTime.Now
let nonLocalDateWithOffset = DateTimeOffset(localTime.Ticks, TimeSpan(2, 0, 0))
printfn $"{nonLocalDateWithOffset}"
// The code produces the following output if run on Feb. 23, 2007:
//    2/23/2007 4:37:50 PM +02:00
Dim localTime As Date = Date.Now
Dim nonLocalDateWithOffset As New DateTimeOffset(localTime.Ticks, _
                                  New TimeSpan(2, 0, 0))
Console.WriteLine(nonLocalDateWithOffset)                                        
'
' The code produces the following output if run on Feb. 23, 2007:
'    2/23/2007 4:37:50 PM +02:00

こちらもご覧ください

  • DateTimeOffset オブジェクト をインスタンス化する

適用対象

DateTimeOffset(DateOnly, TimeOnly, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定した datetime、および offsetを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(DateOnly date, TimeOnly time, TimeSpan offset);
public DateTimeOffset (DateOnly date, TimeOnly time, TimeSpan offset);
new DateTimeOffset : DateOnly * TimeOnly * TimeSpan -> DateTimeOffset
Public Sub New (date As DateOnly, time As TimeOnly, offset As TimeSpan)

パラメーター

date
DateOnly

日付部分。

time
TimeOnly

時間部分。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定した年、月、日、時、分、秒、オフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset);
public DateTimeOffset (int year, int month, int day, int hour, int minute, int second, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * TimeSpan -> DateTimeOffset
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, offset As TimeSpan)

パラメーター

year
Int32

年 (1 から 9999)。

month
Int32

月 (1 ~ 12)。

day
Int32

日 (1 から monthの日数)。

hour
Int32

時間 (0 から 23)。

minute
Int32

分 (0 から 59)。

second
Int32

秒 (0 から 59)。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

例外

offset は、分単位を表すわけではありません。

year が 1 未満または 9999 より大きい。

-又は-

month が 1 より小さいか、12 より大きい。

-又は-

day が 1 日未満か、monthの日数を超えています。

-又は-

hour が 0 より小さいか、23 より大きい。

-又は-

minute が 0 未満または 59 より大きい。

-又は-

second が 0 未満または 59 より大きい。

-又は-

offset が -14 時間未満か、14 時間を超えています。

-又は-

プロパティが DateTimeOffset.MinValue より前か、DateTimeOffset.MaxValueより後です。

次の例では、DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) コンストラクターのオーバーロードを使用して、DateTimeOffset オブジェクトをインスタンス化します。

   DateTime specificDate = new DateTime(2008, 5, 1, 06, 32, 00);
   DateTimeOffset offsetDate = new DateTimeOffset(specificDate.Year,
                                   specificDate.Month,
                                   specificDate.Day,
                                   specificDate.Hour,
                                   specificDate.Minute,
                                   specificDate.Second,
                                   new TimeSpan(-5, 0, 0));
   Console.WriteLine("Current time: {0}", offsetDate);
   Console.WriteLine("Corresponding UTC time: {0}", offsetDate.UtcDateTime);
// The code produces the following output:
//    Current time: 5/1/2008 6:32:00 AM -05:00
//    Corresponding UTC time: 5/1/2008 11:32:00 AM
let specificDate = DateTime(2008, 5, 1, 06, 32, 00)
let offsetDate = DateTimeOffset(specificDate.Year,
                                specificDate.Month,
                                specificDate.Day,
                                specificDate.Hour,
                                specificDate.Minute,
                                specificDate.Second,
                                TimeSpan(-5, 0, 0))
printfn $"Current time: {offsetDate}"
printfn $"Corresponding UTC time: {offsetDate.UtcDateTime}"
// The code produces the following output:
//    Current time: 5/1/2008 6:32:00 AM -05:00
//    Corresponding UTC time: 5/1/2008 11:32:00 AM
   Dim specificDate As Date = #5/1/2008 6:32AM#
   Dim offsetDate As New DateTimeOffset(specificDate.Year, _
                                        specificDate.Month, _
                                        specificDate.Day, _
                                        specificDate.Hour, _
                                        specificDate.Minute, _
                                        specificDate.Second, _
                                        New TimeSpan(-5, 0, 0))
   Console.WriteLine("Current time: {0}", offsetDate)
   Console.WriteLine("Corresponding UTC time: {0}", offsetDate.UtcDateTime)                                              
' The code produces the following output:
'    Current time: 5/1/2008 6:32:00 AM -05:00
'    Corresponding UTC time: 5/1/2008 11:32:00 AM

注釈

このコンストラクターは、グレゴリオ暦の年、月、日として yearmonth、および day を解釈します。 別のカレンダーで年、月、日を使用して DateTimeOffset 値をインスタンス化するには、DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) コンストラクターを呼び出します。

こちらもご覧ください

  • DateTimeOffset オブジェクト をインスタンス化する

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定した年、月、日、時、分、秒、ミリ秒、オフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset);
public DateTimeOffset (int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * TimeSpan -> DateTimeOffset
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, offset As TimeSpan)

パラメーター

year
Int32

年 (1 から 9999)。

month
Int32

月 (1 ~ 12)。

day
Int32

日 (1 から monthの日数)。

hour
Int32

時間 (0 から 23)。

minute
Int32

分 (0 から 59)。

second
Int32

秒 (0 から 59)。

millisecond
Int32

ミリ秒 (0 から 999)。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

例外

offset は、分単位を表すわけではありません。

year が 1 未満または 9999 より大きい。

-又は-

month が 1 より小さいか、12 より大きい。

-又は-

day が 1 日未満か、monthの日数を超えています。

-又は-

hour が 0 より小さいか、23 より大きい。

-又は-

minute が 0 未満または 59 より大きい。

-又は-

second が 0 未満または 59 より大きい。

-又は-

millisecond が 0 未満または 999 より大きい。

-又は-

offset が -14 より小さいか、14 より大きい。

-又は-

プロパティが DateTimeOffset.MinValue より前か、DateTimeOffset.MaxValueより後です。

次の例では、DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) コンストラクターのオーバーロードを使用して、DateTimeOffset オブジェクトをインスタンス化します。

string fmt = "dd MMM yyyy HH:mm:ss";
DateTime thisDate = new DateTime(2007, 06, 12, 19, 00, 14, 16);
DateTimeOffset offsetDate = new DateTimeOffset(thisDate.Year,
                                               thisDate.Month,
                                               thisDate.Day,
                                               thisDate.Hour,
                                               thisDate.Minute,
                                               thisDate.Second,
                                               thisDate.Millisecond,
                                               new TimeSpan(2, 0, 0));
Console.WriteLine("Current time: {0}:{1}", offsetDate.ToString(fmt), offsetDate.Millisecond);
// The code produces the following output:
//    Current time: 12 Jun 2007 19:00:14:16
let fmt = "dd MMM yyyy HH:mm:ss"
let thisDate = DateTime(2007, 06, 12, 19, 00, 14, 16)
let offsetDate = DateTimeOffset(thisDate.Year,
                                thisDate.Month,
                                thisDate.Day,
                                thisDate.Hour,
                                thisDate.Minute,
                                thisDate.Second,
                                thisDate.Millisecond,
                                TimeSpan(2, 0, 0))
printfn $"Current time: {offsetDate.ToString fmt}:{offsetDate.Millisecond}"
// The code produces the following output:
//    Current time: 12 Jun 2007 19:00:14:16
Dim fmt As String = "dd MMM yyyy HH:mm:ss"
Dim thisDate As DateTime = New Date(2007, 06, 12, 19, 00, 14, 16)
Dim offsetDate As New DateTimeOffset(thisDate.Year, _
                                     thisDate.Month, _
                                     thisDate.Day, _
                                     thisDate.Hour, _
                                     thisDate.Minute, _
                                     thisDate.Second, _
                                     thisDate.Millisecond, _ 
                                     New TimeSpan(2, 0, 0))  
Console.WriteLine("Current time: {0}:{1}", offsetDate.ToString(fmt), _ 
                                           offsetDate.Millisecond)
' The code produces the following output:
'    Current time: 12 Jun 2007 19:00:14:16

注釈

このコンストラクターは、グレゴリオ暦の年、月、日として yearmonth、および day を解釈します。 別のカレンダーで年、月、日を使用して DateTimeOffset 値をインスタンス化するには、DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) コンストラクターを呼び出します。

こちらもご覧ください

  • DateTimeOffset オブジェクト をインスタンス化する

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定したカレンダーの年、月、日、時、分、秒、ミリ秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, System::Globalization::Calendar ^ calendar, TimeSpan offset);
public DateTimeOffset (int year, int month, int day, int hour, int minute, int second, int millisecond, System.Globalization.Calendar calendar, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * System.Globalization.Calendar * TimeSpan -> DateTimeOffset
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, calendar As Calendar, offset As TimeSpan)

パラメーター

year
Int32

年。

month
Int32

月 (1 ~ 12)。

day
Int32

日 (1 から monthの日数)。

hour
Int32

時間 (0 から 23)。

minute
Int32

分 (0 から 59)。

second
Int32

秒 (0 から 59)。

millisecond
Int32

ミリ秒 (0 から 999)。

calendar
Calendar

yearmonth、および dayを解釈するために使用されるカレンダー。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

例外

offset は、分単位を表すわけではありません。

calendarnullできません。

year は、calendar パラメーターの MinSupportedDateTime.Year より小さいか、MaxSupportedDateTime.Yearより大きい値です。

-又は-

month は、calendaryear の月数以下です。

-又は-

day が 1 日未満か、monthの日数を超えています。

-又は-

hour が 0 より小さいか、23 より大きい。

-又は-

minute が 0 未満または 59 より大きい。

-又は-

second が 0 未満または 59 より大きい。

-又は-

millisecond が 0 未満または 999 より大きい。

-又は-

offset が -14 時間未満か、14 時間を超えています。

-又は-

yearmonth、および day パラメーターは、日付と時刻の値として表すことはできません。

-又は-

プロパティが DateTimeOffset.MinValue より前か、DateTimeOffset.MaxValueより後です。

次の例では、HebrewCalendar クラスと HijriCalendar クラスの両方のインスタンスを使用して、DateTimeOffset 値をインスタンス化します。 その日付は、それぞれのカレンダーとグレゴリオ暦を使用してコンソールに表示されます。

CultureInfo fmt;
int year;
Calendar cal;
DateTimeOffset dateInCal;

// Instantiate DateTimeOffset with Hebrew calendar
year = 5770;
cal = new HebrewCalendar();
fmt = new CultureInfo("he-IL");
fmt.DateTimeFormat.Calendar = cal;
dateInCal = new DateTimeOffset(year, 7, 12,
                               15, 30, 0, 0,
                               cal,
                               new TimeSpan(2, 0, 0));
// Display the date in the Hebrew calendar
Console.WriteLine("Date in Hebrew Calendar: {0:g}",
                   dateInCal.ToString(fmt));
// Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);
Console.WriteLine();

// Instantiate DateTimeOffset with Hijri calendar
year = 1431;
cal = new HijriCalendar();
fmt = new CultureInfo("ar-SA");
fmt.DateTimeFormat.Calendar = cal;
dateInCal = new DateTimeOffset(year, 7, 12,
                               15, 30, 0, 0,
                               cal,
                               new TimeSpan(2, 0, 0));
// Display the date in the Hijri calendar
Console.WriteLine("Date in Hijri Calendar: {0:g}",
                   dateInCal.ToString(fmt));
// Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);
Console.WriteLine();
// Instantiate DateTimeOffset with Hebrew calendar
let year = 5770
let cal = HebrewCalendar()
let fmt = CultureInfo "he-IL"
fmt.DateTimeFormat.Calendar <- cal
let dateInCal = DateTimeOffset(year, 7, 12,
                               15, 30, 0, 0,
                               cal,
                               TimeSpan(2, 0, 0))
// Display the date in the Hebrew calendar
printfn $"Date in Hebrew Calendar: {dateInCal.ToString fmt:g}"
// Display the date in the Gregorian calendar
printfn $"Date in Gregorian Calendar: {dateInCal:g}\n"

// Instantiate DateTimeOffset with Hijri calendar
let year = 1431
let cal = HijriCalendar()
let fmt = CultureInfo "ar-SA"
fmt.DateTimeFormat.Calendar <- cal
let dateInCal = DateTimeOffset(year, 7, 12,
                               15, 30, 0, 0,
                               cal,
                               TimeSpan(2, 0, 0))
// Display the date in the Hijri calendar
printfn $"Date in Hijri Calendar: {dateInCal.ToString fmt:g}"
// Display the date in the Gregorian calendar
printfn $"Date in Gregorian Calendar: {dateInCal:g}\n"
Dim fmt As CultureInfo
Dim year As Integer
Dim cal As Calendar
Dim dateInCal As DateTimeOffset

' Instantiate DateTimeOffset with Hebrew calendar
year = 5770
cal = New HebrewCalendar()
fmt = New CultureInfo("he-IL")
fmt.DateTimeFormat.Calendar = cal      
dateInCal = New DateTimeOffset(year, 7, 12, _
                               15, 30, 0, 0, _
                               cal, _
                               New TimeSpan(2, 0, 0))
' Display the date in the Hebrew calendar
Console.WriteLine("Date in Hebrew Calendar: {0:g}", _
                   dateInCal.ToString(fmt))
' Display the date in the Gregorian calendar                         
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal)
Console.WriteLine()

' Instantiate DateTimeOffset with Hijri calendar
year = 1431
cal = New HijriCalendar()
fmt = New CultureInfo("ar-SA")
fmt.DateTimeFormat.Calendar = cal
dateInCal = New DateTimeOffset(year, 7, 12, _
                               15, 30, 0, 0, _
                               cal, _
                               New TimeSpan(2, 0, 0))
' Display the date in the Hijri calendar
Console.WriteLine("Date in Hijri Calendar: {0:g}", _
                   dateInCal.ToString(fmt))
' Display the date in the Gregorian calendar                         
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal)
Console.WriteLine()

注釈

yearmonthdayhourminutesecond、および millisecond パラメーターはすべて、calendar パラメーターで指定されたカレンダーで表される値を反映します。 これらの値が、このカレンダーを使用して表現できない日付と時刻を形成する場合は、例外がスローされます。

大事な

日本暦の年号は天皇の治世に基づいているため、変化することが期待されます。 たとえば、2019 年 5 月 1 日は、JapaneseCalendarJapaneseLunisolarCalendarで令和元年の始まりを示しました。 このような時代の変化は、これらのカレンダーを使用するすべてのアプリケーションに影響します。 詳細およびアプリケーションが影響を受けるかどうかを確認するには、「.NETの日本語カレンダーで新しい時代 (年号) を処理する を参照してください。 Windows システム上でアプリケーションをテストして時代 (年号) の変更に対する準備を確認する方法については、「日本の時代 (年号) の変更に対応するためのアプリケーションの準備」を参照してください。 複数の時代 (年号) を含むカレンダーをサポートする .NET の機能と、複数の時代 (年号) をサポートするカレンダーを使用する場合のベスト プラクティスについては、「年号の使用」を参照してください。

こちらもご覧ください

  • DateTimeOffset オブジェクト をインスタンス化する

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定した yearmonthdayhourminutesecondmillisecondmicrosecond、および offsetを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, TimeSpan offset);
public DateTimeOffset (int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * int * TimeSpan -> DateTimeOffset
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, microsecond As Integer, offset As TimeSpan)

パラメーター

year
Int32

年 (1 から 9999)。

month
Int32

月 (1 ~ 12)。

day
Int32

日 (1 から monthの日数)。

hour
Int32

時間 (0 から 23)。

minute
Int32

分 (0 から 59)。

second
Int32

秒 (0 から 59)。

millisecond
Int32

ミリ秒 (0 から 999)。

microsecond
Int32

マイクロ秒 (0 から 999)。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

例外

offset は、分単位を表すわけではありません。

year が 1 より小さいか、9999 より大きい。

-又は-

month が 1 より小さいか、12 より大きい。

-又は-

day が 1 未満か、monthの日数より大きい。

-又は-

hour が 0 未満または 23 より大きい。

-又は-

minute が 0 未満または 59 より大きい。

-又は-

second が 0 未満または 59 より大きい。

-又は-

millisecond が 0 未満または 999 より大きい。

-又は-

microsecond が 0 未満または 999 より大きい。

注釈

このコンストラクターは、グレゴリオ暦の年、月、日として yearmonth、および day を解釈します。 別のカレンダーで年、月、日を使用して DateTimeOffset 値をインスタンス化するには、DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) コンストラクターを呼び出します。

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs
ソース:
DateTimeOffset.cs

指定した yearmonthdayhourminutesecondmillisecondmicrosecond、および offsetを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

public:
 DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System::Globalization::Calendar ^ calendar, TimeSpan offset);
public DateTimeOffset (int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System.Globalization.Calendar calendar, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * int * System.Globalization.Calendar * TimeSpan -> DateTimeOffset
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, microsecond As Integer, calendar As Calendar, offset As TimeSpan)

パラメーター

year
Int32

年 (1 から 9999)。

month
Int32

月 (1 ~ 12)。

day
Int32

日 (1 から monthの日数)。

hour
Int32

時間 (0 から 23)。

minute
Int32

分 (0 から 59)。

second
Int32

秒 (0 から 59)。

millisecond
Int32

ミリ秒 (0 から 999)。

microsecond
Int32

マイクロ秒 (0 から 999)。

calendar
Calendar

yearmonth、および dayを解釈するために使用されるカレンダー。

offset
TimeSpan

協定世界時 (UTC) からの時刻のオフセット。

例外

offset は、分単位を表すわけではありません。

year が、calendarでサポートされている範囲内にありません。

-又は-

month が 1 より小さいか、calendarの月数より大きい。

-又は-

day が 1 未満か、monthの日数より大きい。

-又は-

hour が 0 未満または 23 より大きい。

-又は-

minute が 0 未満または 59 より大きい。

-又は-

second が 0 未満または 59 より大きい。

-又は-

millisecond が 0 未満または 999 より大きい。

-又は-

microsecond が 0 未満または 999 より大きい。

-又は-

offset が -14 時間未満か、14 時間を超えています。

-又は-

yearmonth、および day パラメーターは、日付と時刻の値として表すことはできません。

-又は-

UtcDateTime プロパティが MinValue より前か、MaxValueより後です。

注釈

このコンストラクターは、グレゴリオ暦の年、月、日として yearmonth、および day を解釈します。 別のカレンダーで年、月、日を使用して DateTimeOffset 値をインスタンス化するには、DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) コンストラクターを呼び出します。

適用対象