这段代码长期以来一直在运行,但现在当我尝试将 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属性未正确设置。我已经通过Google和SO查找了示例,但我并不真正理解错误消息。
任何建议都将不胜感激。
问候。
编辑-确切的错误消息是:
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
EDIT: outageEndDate.Kind = Utc
outageEndDate
的 DateTimeKind 是什么?Debug.WriteLine(string.Format("{0}", outageEndDate.Kind));
- Monroe Thomas