該代碼已經工作了很長時間了,但現在已經打破了,當我試圖通過DateTime.Now作爲outageEndDate參數:轉換DateTime.Now到不同的時區
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);
錯誤消息我我得到的最後一行是Kind屬性設置不正確的日期時間參數(outageEndDate)。我谷歌搜索和檢查的例子,但我真的不明白錯誤信息。
任何建議表示讚賞。
問候。
編輯 - 確切的錯誤信息是:
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
請發佈確切的錯誤謝謝 – MethodMan 2012-08-08 20:55:52
什麼是DateTimeKind for outageEndDate? '的Debug.WriteLine(的String.Format( 「{0}」,outageEndDate.Kind));' – 2012-08-08 21:02:40
@DJKRAZE:見編輯到OP。 – Kevin 2012-08-08 21:10:51