Create DateTimeOffset from specified year, month, day, hour, minute, second, and offset in CSharp
Description
The following code shows how to create DateTimeOffset from specified year, month, day, hour, minute, second, and offset.
Example
/*from w w w. ja v a 2s . com*/
using System;
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.