本文整理汇总了C#中System.TimeZoneInfo.GetSystemTimeZones方法的典型用法代码示例。如果您正苦于以下问题:C# TimeZoneInfo.GetSystemTimeZones方法的具体用法?C# TimeZoneInfo.GetSystemTimeZones怎么用?C# TimeZoneInfo.GetSystemTimeZones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了TimeZoneInfo.GetSystemTimeZones方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Globalization;
using System.IO;
using System.Collections.ObjectModel;
public class Example
{
public static void Main()
{
const string OUTPUTFILENAME = @"C:\Temp\TimeZoneInfo.txt";
DateTimeFormatInfo dateFormats = CultureInfo.CurrentCulture.DateTimeFormat;
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
StreamWriter sw = new StreamWriter(OUTPUTFILENAME, false);
foreach (TimeZoneInfo timeZone in timeZones)
{
bool hasDST = timeZone.SupportsDaylightSavingTime;
TimeSpan offsetFromUtc = timeZone.BaseUtcOffset;
TimeZoneInfo.AdjustmentRule[] adjustRules;
string offsetString;
sw.WriteLine("ID: {0}", timeZone.Id);
sw.WriteLine(" Display Name: {0, 40}", timeZone.DisplayName);
sw.WriteLine(" Standard Name: {0, 39}", timeZone.StandardName);
sw.Write(" Daylight Name: {0, 39}", timeZone.DaylightName);
sw.Write(hasDST ? " ***Has " : " ***Does Not Have ");
sw.WriteLine("Daylight Saving Time***");
offsetString = String.Format("{0} hours, {1} minutes", offsetFromUtc.Hours, offsetFromUtc.Minutes);
sw.WriteLine(" Offset from UTC: {0, 40}", offsetString);
adjustRules = timeZone.GetAdjustmentRules();
sw.WriteLine(" Number of adjustment rules: {0, 26}", adjustRules.Length);
if (adjustRules.Length > 0)
{
sw.WriteLine(" Adjustment Rules:");
foreach (TimeZoneInfo.AdjustmentRule rule in adjustRules)
{
TimeZoneInfo.TransitionTime transTimeStart = rule.DaylightTransitionStart;
TimeZoneInfo.TransitionTime transTimeEnd = rule.DaylightTransitionEnd;
sw.WriteLine(" From {0} to {1}", rule.DateStart, rule.DateEnd);
sw.WriteLine(" Delta: {0}", rule.DaylightDelta);
if (! transTimeStart.IsFixedDateRule)
{
sw.WriteLine(" Begins at {0:t} on {1} of week {2} of {3}", transTimeStart.TimeOfDay,
transTimeStart.DayOfWeek,
transTimeStart.Week,
dateFormats.MonthNames[transTimeStart.Month - 1]);
sw.WriteLine(" Ends at {0:t} on {1} of week {2} of {3}", transTimeEnd.TimeOfDay,
transTimeEnd.DayOfWeek,
transTimeEnd.Week,
dateFormats.MonthNames[transTimeEnd.Month - 1]);
}
else
{
sw.WriteLine(" Begins at {0:t} on {1} {2}", transTimeStart.TimeOfDay,
transTimeStart.Day,
dateFormats.MonthNames[transTimeStart.Month - 1]);
sw.WriteLine(" Ends at {0:t} on {1} {2}", transTimeEnd.TimeOfDay,
transTimeEnd.Day,
dateFormats.MonthNames[transTimeEnd.Month - 1]);
}
}
}
}
sw.Close();
}
}