1 回答
TA贡献1775条经验 获得超8个赞
using System;
using System.Globalization;
namespace TestingApp
{
class Program
{
static void Main(string[] args)
{
var tz = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
string[] times = {
// In 1995 :
// last sunday in september was sept. 24th
// last sunday in october was oct. 29th
"1995/09/23 12:00:00", "1995/09/24 12:00:00",
"1995/10/28 12:00:00", "1995/10/29 12:00:00",
};
foreach (var t in times) {
var utc = DateTime.ParseExact(t, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None);
utc = TimeZoneInfo.ConvertTime(utc, tz, TimeZoneInfo.Utc);
Console.WriteLine(String.Format("Paris: {0} -> UTC: {1}", t, utc.ToString()));
}
}
}
}
// Output :
// Paris: 1995/09/23 12:00:00 -> UTC: 23/09/1995 10:00:00
// Paris: 1995/09/24 12:00:00 -> UTC: 24/09/1995 10:00:00 <- instead of 11:00:00 UTC
// Paris: 1995/10/28 12:00:00 -> UTC: 28/10/1995 10:00:00 <- instead of 11:00:00 UTC
// Paris: 1995/10/29 12:00:00 -> UTC: 29/10/1995 11:00:00
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报