本文整理匯總了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.