Mega Code Archive

 
Categories / C# / Date Time
 

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

using System; using System.Globalization; using System.Collections.ObjectModel; public class TimeOffsets {     public static void Main()     {         CultureInfo fmt;         int year;         Calendar cal;         DateTimeOffset dateInCal;         // Instantiate DateTimeOffset with Hebrew calendar         year = 5770;         cal = new HebrewCalendar();         fmt = new CultureInfo("he-IL");         fmt.DateTimeFormat.Calendar = cal;         dateInCal = new DateTimeOffset(year, 7, 12, 15, 30, 0, 0, cal, new TimeSpan(10, 0, 0));         Console.WriteLine("Date in Hebrew Calendar: {0:g}", dateInCal.ToString(fmt));         Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);     } }