c#获取指定时区的日期

时间:2021-05-27 21:02:38

1、首先将服务器的时间转化为utc时间,然后转换成指定时区的日期

public DateTime GetSpecificZoneNowDate(string zoneName = "China Standard Time")
{
var utcdate = DateTime.Now.ToUniversalTime();
var beiJingZone = TimeZoneInfo.FindSystemTimeZoneById(zoneName);
return TimeZoneInfo.ConvertTimeFromUtc(utcdate, beiJingZone);
}