public void SimplePstConversionTest() { WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST Console.WriteLine(pst.ToLocalTime(DateTime.UtcNow)); Console.WriteLine(TimeZone.CurrentTimeZone.ToLocalTime(DateTime.UtcNow)); }
public void ToLocalTimeReturnsProperTimeDuringDaylightSavings() { IFormatProvider culture = new CultureInfo("en-US", true); DateTime utcDate = DateTime.Parse("10/01/2006 19:30", culture, DateTimeStyles.AllowWhiteSpaces); utcDate = utcDate.ToLocalTime().ToUniversalTime(); Assert.AreEqual("10/01/2006 19:30", utcDate.ToString("MM/dd/yyyy HH:mm", culture), "An assumption about round tripping the UTC date was wrong."); WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST DateTime pstDate = pst.ToLocalTime(utcDate); string formattedPstDate = pstDate.ToString("MM/dd/yyyy HH:mm", culture); Assert.AreEqual("10/01/2006 12:30", formattedPstDate); }