本文整理匯總了C#中System.DateTimeOffset.DateTimeOffset構造函數的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeOffset構造函數的具體用法?C# DateTimeOffset怎麽用?C# DateTimeOffset使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset構造函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DateTimeOffset
DateTime localNow = DateTime.Now;
DateTimeOffset localOffset = new DateTimeOffset(localNow);
Console.WriteLine(localOffset.ToString());
DateTime utcNow = DateTime.UtcNow;
DateTimeOffset utcOffset = new DateTimeOffset(utcNow);
Console.WriteLine(utcOffset.ToString());
DateTime unspecifiedNow = DateTime.SpecifyKind(DateTime.Now,
DateTimeKind.Unspecified);
DateTimeOffset unspecifiedOffset = new DateTimeOffset(unspecifiedNow);
Console.WriteLine(unspecifiedOffset.ToString());
//
// The code produces the following output if run on Feb. 23, 2007, on
// a system 8 hours earlier than UTC:
// 2/23/2007 4:21:58 PM -08:00
// 2/24/2007 12:21:58 AM +00:00
// 2/23/2007 4:21:58 PM -08:00
示例2: DateTime
DateTime localTime = new DateTime(2007, 07, 12, 06, 32, 00);
DateTimeOffset dateAndOffset = new DateTimeOffset(localTime,
TimeZoneInfo.Local.GetUtcOffset(localTime));
Console.WriteLine(dateAndOffset);
輸出:
7/12/2007 6:32:00 AM -07:00
示例3: DateTime
DateTime dateWithoutOffset = new DateTime(2007, 7, 16, 13, 32, 00);
DateTimeOffset timeFromTicks = new DateTimeOffset(dateWithoutOffset.Ticks,
new TimeSpan(-5, 0, 0));
Console.WriteLine(timeFromTicks.ToString());
輸出:
7/16/2007 1:32:00 PM -05:00
示例4: DateTimeOffset
DateTime localTime = DateTime.Now;
DateTimeOffset nonLocalDateWithOffset = new DateTimeOffset(localTime.Ticks,
new TimeSpan(2, 0, 0));
Console.WriteLine(nonLocalDateWithOffset);
//
// The code produces the following output if run on Feb. 23, 2007:
// 2/23/2007 4:37:50 PM +02:00
示例5: DateTime
DateTime specificDate = new DateTime(2008, 5, 1, 06, 32, 00);
DateTimeOffset offsetDate = new DateTimeOffset(specificDate.Year,
specificDate.Month,
specificDate.Day,
specificDate.Hour,
specificDate.Minute,
specificDate.Second,
new TimeSpan(-5, 0, 0));
Console.WriteLine("Current time: {0}", offsetDate);
Console.WriteLine("Corresponding UTC time: {0}", offsetDate.UtcDateTime);
輸出:
Current time: 5/1/2008 6:32:00 AM -05:00 Corresponding UTC time: 5/1/2008 11:32:00 AM
示例6: DateTime
string fmt = "dd MMM yyyy HH:mm:ss";
DateTime thisDate = new DateTime(2007, 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);
輸出:
Current time: 12 Jun 2007 19:00:14:16
示例7: HebrewCalendar
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(2, 0, 0));
// Display the date in the Hebrew calendar
Console.WriteLine("Date in Hebrew Calendar: {0:g}",
dateInCal.ToString(fmt));
// Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);
Console.WriteLine();
// Instantiate DateTimeOffset with Hijri calendar
year = 1431;
cal = new HijriCalendar();
fmt = new CultureInfo("ar-SA");
fmt.DateTimeFormat.Calendar = cal;
dateInCal = new DateTimeOffset(year, 7, 12,
15, 30, 0, 0,
cal,
new TimeSpan(2, 0, 0));
// Display the date in the Hijri calendar
Console.WriteLine("Date in Hijri Calendar: {0:g}",
dateInCal.ToString(fmt));
// Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);
Console.WriteLine();