C# DateTimeOffset DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
Description
DateTimeOffset DateTimeOffset(Int32, Int32, Int32, Int32,
Int32, Int32, Int32, TimeSpan)
initializes a new instance of the
DateTimeOffset structure using the specified year, month, day, hour, minute,
second, millisecond, and offset.
Syntax
DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
has the following syntax.
public DateTimeOffset(
int year,/*from w ww. j a v a 2s . com*/
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
TimeSpan offset
)
Parameters
DateTimeOffset.DateTimeOffset(Int32, 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).millisecond
- The milliseconds (0 through 999).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, Int32, TimeSpan) constructor overload.
using System;/*w w w . ja v a 2 s .c om*/
using System.Globalization;
public class MainClass{
public static void Main(String[] argv){
string fmt = "dd MMM yyyy HH:mm:ss";
DateTime thisDate = new DateTime(2015, 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 above generates the following result.