本文整理汇总了C#中System.DateTimeOffset.ToLocalTime方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.ToLocalTime方法的具体用法?C# DateTimeOffset.ToLocalTime怎么用?C# DateTimeOffset.ToLocalTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.ToLocalTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DateTimeOffset
// Local time changes on 3/11/2007 at 2:00 AM
DateTimeOffset originalTime, localTime;
originalTime = new DateTimeOffset(2007, 3, 11, 3, 0, 0,
new TimeSpan(-6, 0, 0));
localTime = originalTime.ToLocalTime();
Console.WriteLine("Converted {0} to {1}.", originalTime.ToString(),
localTime.ToString());
originalTime = new DateTimeOffset(2007, 3, 11, 4, 0, 0,
new TimeSpan(-6, 0, 0));
localTime = originalTime.ToLocalTime();
Console.WriteLine("Converted {0} to {1}.", originalTime.ToString(),
localTime.ToString());
// Define a summer UTC time
originalTime = new DateTimeOffset(2007, 6, 15, 8, 0, 0,
TimeSpan.Zero);
localTime = originalTime.ToLocalTime();
Console.WriteLine("Converted {0} to {1}.", originalTime.ToString(),
localTime.ToString());
// Define a winter time
originalTime = new DateTimeOffset(2007, 11, 30, 14, 0, 0,
new TimeSpan(3, 0, 0));
localTime = originalTime.ToLocalTime();
Console.WriteLine("Converted {0} to {1}.", originalTime.ToString(),
localTime.ToString());
输出:
Converted 3/11/2007 3:00:00 AM -06:00 to 3/11/2007 1:00:00 AM -08:00. Converted 3/11/2007 4:00:00 AM -06:00 to 3/11/2007 3:00:00 AM -07:00. Converted 6/15/2007 8:00:00 AM +00:00 to 6/15/2007 1:00:00 AM -07:00. Converted 11/30/2007 2:00:00 PM +03:00 to 11/30/2007 3:00:00 AM -08:00.