Skip to content

Instantly share code, notes, and snippets.

@steentottrup
Created December 22, 2016 07:15
Show Gist options
  • Save steentottrup/86ec8728d6d2781c88e35c5805a1b84f to your computer and use it in GitHub Desktop.
Save steentottrup/86ec8728d6d2781c88e35c5805a1b84f to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
namespace ConsoleApplication3 {
class Program {
static void Main(string[] args) {
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
DateTime postedDk = new DateTime(2016, 12, 17, 6, 28, 0, DateTimeKind.Local);
DateTime postedUtc = TimeZoneInfo.ConvertTime(postedDk, TimeZoneInfo.Local, TimeZoneInfo.Utc);
DateTime postedMountain = TimeZoneInfo.ConvertTime(postedDk, TimeZoneInfo.Local, TimeZoneInfo.GetSystemTimeZones()[12]);
TimeZoneInfo mountain = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
Console.WriteLine($"Posted by me, in Denmark, at {postedDk.ToLongDateString()} {postedDk.ToLongTimeString()} local time");
Console.WriteLine($"That's UTC: {postedUtc.ToLongDateString()} {postedUtc.ToLongTimeString()} UTC");
Console.WriteLine($"And displays as {mountain.DisplayName} time: {postedMountain.ToLongDateString()} {postedMountain.ToLongTimeString()}");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment