2015-10-26 91 views
1

出於某種原因,我的代碼無法正常工作,它可能位於contacthours.Hours1Fromcontacthours.Hours1To部件上。DateTime.ParseExact無法正常工作

ExtendedContactDetailsType contactdetails = new ExtendedContactDetailsType(); 
contactdetails.ClassifiedAdContactByEmailEnabled = true; 
ContactHoursDetailsType contacthours = new ContactHoursDetailsType(); 
contacthours.Hours1AnyTime = false; 
contacthours.Hours1Days = DaysCodeType.Weekdays; 
contacthours.Hours1From = DateTime.ParseExact("08:00", "hh:mm", null); 
contacthours.Hours1To = DateTime.ParseExact("16:00", "hh:mm", null); 
contacthours.TimeZoneID = "Eastern"; 
contactdetails.ContactHoursDetails = contacthours; 

item.ExtendedSellerContactDetails = contactdetails; 
+6

你的意思是「工作不正常」你面臨的問題是什麼?預期的行爲是什麼? – Shyju

+4

我們無法猜測「不工作」是什麼意思。 –

+1

簡單的解決方案 - 使用調試器,進入你的代碼並檢查'contacthours.Hours1From'和'contacthours.Hours2From'的值,並確保它們可以解析爲'DateTime'。它最有可能比等待別人抓住他們的SO水晶球更快...... – Tim

回答

3

第一的問題是,你不使用24小時小時格式字符串:

contacthours.Hours1From = DateTime.ParseExact("08:00", "HH:mm", null); 
contacthours.Hours1To = DateTime.ParseExact("16:00", "HH:mm", null); 

不管是不是這就是唯一的問題目前還不清楚。

+0

這是得到的功能:private System.DateTime mHours1From; [System.Xml.Serialization.XmlElementAttribute(DataType =「time」)] public System.DateTime Hours1From { get { return this.mHours1From; } set { this.mHours1From = value; this.mHours1FromSpecified = true; } }所以我應該真的使用parseexact? –

+0

我很困惑 - 你是從API還是_sending_開始創建一個時間?你是否正在對時代進行硬編碼,還是來自API? –

+0

不,我正在發送這個時間,我試圖告訴你的函數Hour1From的setter函數的源代碼,以確保它是否適合使用我的parseexact函數來設置它.. –