C# DateTimeOffset DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)
Description
DateTimeOffset DateTimeOffset(Int32, Int32, Int32, Int32,
Int32, Int32, Int32, Calendar, TimeSpan)
initializes a new instance
of the DateTimeOffset structure using the specified year, month, day, hour,
minute, second, millisecond, and offset of a specified calendar.
Syntax
DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)
has the following syntax.
public DateTimeOffset(
int year,//w w w . jav a 2 s .c o m
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
Calendar calendar,
TimeSpan offset
)
Parameters
DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)
has the following parameters.
year
- The year.month
- The month (1 through 12).day
- The day (1 through the number of days in month).hour
- The hours (0 through 23).minute
- The minutes (0 through 59).second
- The seconds (0 through 59).millisecond
- The milliseconds (0 through 999).calendar
- The calendar that is used to interpret year, month, and day.offset
- The time's offset from Coordinated Universal Time (UTC).
Example
The following example uses instances of both the HebrewCalendar class and the HijriCalendar class to instantiate a DateTimeOffset value.
using System;//from w ww. ja v a2s. com
using System.Globalization;
public class MainClass{
public static void Main(String[] argv){
int year = 2014;
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.