CreateDateTimeOffset from year, month, day, hour, minute, second, millisecond, and offset in CSharp
Description
The following code shows how to createDateTimeOffset from year, month, day, hour, minute, second, millisecond, and offset.
Example
/*from w ww . j a v a 2 s. co m*/
using System;
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.