C# DateTimeOffset DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
Description
DateTimeOffset DateTimeOffset(Int32, Int32, Int32, Int32,
Int32, Int32, TimeSpan)
initializes a new instance of the DateTimeOffset
structure using the specified year, month, day, hour, minute, second, and
offset.
Syntax
DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
has the following syntax.
public DateTimeOffset(
int year,/* www.j av a 2 s.c o m*/
int month,
int day,
int hour,
int minute,
int second,
TimeSpan offset
)
Parameters
DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
has the following parameters.
year
- The year (1 through 9999).month
- The month (1 through 12).day
- The day (1 through the number of days in month).hour
- The hours (0 through 23).minute
- The minutes (0 through 59).second
- The seconds (0 through 59).offset
- The time's offset from Coordinated Universal Time (UTC).
Example
The following example instantiates a DateTimeOffset object by using the DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) constructor overload.
using System;/* w ww .j a v a2s . c o m*/
using System.Globalization;
public class MainClass{
public static void Main(String[] argv){
DateTime specificDate = new DateTime(2015, 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 above generates the following result.