Skip to content

Instantly share code, notes, and snippets.

@jon-adams
Created January 20, 2017 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jon-adams/e18fefa490cdddd32ecb290b655de45b to your computer and use it in GitHub Desktop.
Save jon-adams/e18fefa490cdddd32ecb290b655de45b to your computer and use it in GitHub Desktop.
Export Time Zone list from .Net
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