Created
January 20, 2017 17:05
-
-
Save jon-adams/e18fefa490cdddd32ecb290b655de45b to your computer and use it in GitHub Desktop.
Export Time Zone list from .Net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
public class MyClass | |
{ | |
public static void RunSnippet() | |
{ | |
// get collection of time zones | |
System.TimeZoneInfo.GetSystemTimeZones(); | |
// get string version of applicable fields | |
Console.Write( | |
String.Join("\n", System.TimeZoneInfo.GetSystemTimeZones() | |
.OrderBy(o => o.BaseUtcOffset).ThenBy(o => o.Id) | |
.Select(o => "\"" + o.Id + "\" " + o.BaseUtcOffset + " DST: " + (o.SupportsDaylightSavingTime ? "yes" : "no")) | |
.ToArray()) | |
+ "\n" | |
); | |
} | |
#region Helper methods | |
public static void Main() | |
{ | |
try | |
{ | |
RunSnippet(); | |
} | |
catch (Exception e) | |
{ | |
string error = string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString()); | |
Console.WriteLine(error); | |
} | |
finally | |
{ | |
Console.Write("Press any key to continue..."); | |
Console.ReadKey(); | |
} | |
} | |
private static void WL(object text, params object[] args) | |
{ | |
Console.WriteLine(text.ToString(), args); | |
} | |
private static void RL() | |
{ | |
Console.ReadLine(); | |
} | |
private static void Break() | |
{ | |
System.Diagnostics.Debugger.Break(); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment