这段代码已经工作了很长时间,但是当我尝试将 DateTime.Now 作为 outageEndDate 参数传递时,它现在已经损坏:
public Outage(DateTime outageStartDate, DateTime outageEndDate, Dictionary<string, string> weeklyHours, string province, string localProvince)
{
this.outageStartDate = outageStartDate;
this.outageEndDate = outageEndDate;
this.weeklyHours = weeklyHours;
this.province = province;
localTime = TimeZoneInfo.FindSystemTimeZoneById(timeZones[localProvince]);
if (outageStartDate < outageEndDate)
{
TimeZoneInfo remoteTime = TimeZoneInfo.FindSystemTimeZoneById(timeZones[province]);
outageStartDate = TimeZoneInfo.ConvertTime(outageStartDate, localTime, remoteTime);
outageEndDate = TimeZoneInfo.ConvertTime(outageEndDate, localTime, remoteTime);
我在最后一行收到的错误消息是 DateTime 参数 (outageEndDate) 上的 Kind 属性设置不正确。我已经用谷歌搜索并检查了示例,但我并不真正理解错误消息。
任何建议表示赞赏。
问候。
编辑 - 确切的错误信息是:
The conversion could not be completed because the supplied DateTime did not have the Kind
property set correctly. For example, when the Kind property is DateTimeKind.Local, the source
time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone
编辑:outageEndDate.Kind = Utc