本文整理匯總了C#中System.DateTimeOffset.LocalDateTime屬性的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeOffset.LocalDateTime屬性的具體用法?C# DateTimeOffset.LocalDateTime怎麽用?C# DateTimeOffset.LocalDateTime使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.LocalDateTime屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DateTimeOffset
DateTimeOffset dto;
// Current time
dto = DateTimeOffset.Now;
Console.WriteLine(dto.LocalDateTime);
// UTC time
dto = DateTimeOffset.UtcNow;
Console.WriteLine(dto.LocalDateTime);
// Transition to DST in local time zone occurs on 3/11/2007 at 2:00 AM
dto = new DateTimeOffset(2007, 3, 11, 3, 30, 0, new TimeSpan(-7, 0, 0));
Console.WriteLine(dto.LocalDateTime);
dto = new DateTimeOffset(2007, 3, 11, 2, 30, 0, new TimeSpan(-7, 0, 0));
Console.WriteLine(dto.LocalDateTime);
// Invalid time in local time zone
dto = new DateTimeOffset(2007, 3, 11, 2, 30, 0, new TimeSpan(-8, 0, 0));
Console.WriteLine(TimeZoneInfo.Local.IsInvalidTime(dto.DateTime));
Console.WriteLine(dto.LocalDateTime);
// Transition from DST in local time zone occurs on 11/4/07 at 2:00 AM
// This is an ambiguous time
dto = new DateTimeOffset(2007, 11, 4, 1, 30, 0, new TimeSpan(-7, 0, 0));
Console.WriteLine(TimeZoneInfo.Local.IsAmbiguousTime(dto));
Console.WriteLine(dto.LocalDateTime);
dto = new DateTimeOffset(2007, 11, 4, 2, 30, 0, new TimeSpan(-7, 0, 0));
Console.WriteLine(TimeZoneInfo.Local.IsAmbiguousTime(dto));
Console.WriteLine(dto.LocalDateTime);
// This is also an ambiguous time
dto = new DateTimeOffset(2007, 11, 4, 1, 30, 0, new TimeSpan(-8, 0, 0));
Console.WriteLine(TimeZoneInfo.Local.IsAmbiguousTime(dto));
Console.WriteLine(dto.LocalDateTime);
// If run on 3/8/2007 at 4:56 PM, the code produces the following
// output:
// 3/8/2007 4:56:03 PM
// 3/8/2007 4:56:03 PM
// 3/11/2007 3:30:00 AM
// 3/11/2007 1:30:00 AM
// True
// 3/11/2007 3:30:00 AM
// True
// 11/4/2007 1:30:00 AM
// 11/4/2007 1:30:00 AM
// True
// 11/4/2007 1:30:00 AM