Mega Code Archive

 
Categories / C# / Date Time
 

Create DateTimeOffset using the specified year, month, day, hour, minute, second, millisecond, and offset

using System; using System.Collections.ObjectModel; public class TimeOffsets {    public static void Main()    {         string fmt = "dd MMM yyyy HH:mm:ss";         DateTime thisDate = new DateTime(2010, 08, 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);    } }