Create DateTimeOffset from year, month, day, hour, minute, second, millisecond, and offset of a calendar in CSharp

Description

The following code shows how to create DateTimeOffset from year, month, day, hour, minute, second, millisecond, and offset of a calendar.

Example


using System;/*from  ww  w .  j  a v  a 2s  .co m*/
using System.Globalization;
public class MainClass{
  public static void Main(String[] argv){  
    int year = 5344;
    Calendar cal = new HebrewCalendar();
    DateTimeOffset dateInCal;
    CultureInfo fmt = new CultureInfo("he-IL");
    fmt.DateTimeFormat.Calendar = cal;      
    dateInCal = new DateTimeOffset(year, 7, 12, 
                                   15, 30, 0, 0, 
                                   cal, 
                                   new TimeSpan(2, 0, 0));

    Console.WriteLine("Date in Hebrew Calendar: {0:g}", 
                       dateInCal.ToString(fmt));

    Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var