c# .net 时间格式化,怎样设置英国时区?



 private static SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z", Locale.ENGLISH);
  String startTime = formatter.format(new Date());//请求时间

能帮我用c#代码写上面这段Java代码吗?

datetime java .net c#

五更玖琉璃 9 years, 2 months ago

 // 查看当前系统支持的所有时区,主要是用 StandardName,
// 不过 ToString() 会显示时间差以及城市,可以帮忙人工判断
// foreach (var z in TimeZoneInfo.GetSystemTimeZones()) {
//   Console.WriteLine($"{z.StandardName} - ${z}");
// }

// 获取英国的时区
TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
Console.WriteLine(zone);

Console.WriteLine(DateTime.Now.Kind);     // Local
var gtmTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, zone);
Console.WriteLine(gtmTime);

var d = new DateTime(2015, 9, 1, 18, 0, 0, DateTimeKind.Utc);
Console.WriteLine(d.Kind);    // Utc
Console.WriteLine(TimeZoneInfo.ConvertTime(d, TimeZoneInfo.Utc, zone));

forjune answered 9 years, 2 months ago

Your Answer