Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DateTime.ParseExact无法正常工作_C#_Asp.net_Ebay Api - Fatal编程技术网

C# DateTime.ParseExact无法正常工作

C# DateTime.ParseExact无法正常工作,c#,asp.net,ebay-api,C#,Asp.net,Ebay Api,由于某些原因,我的代码不起作用,它可能位于从到部分的contacthours.hours1和contacthours1上 ExtendedContactDetailsType contactdetails = new ExtendedContactDetailsType(); contactdetails.ClassifiedAdContactByEmailEnabled = true; ContactHoursDetailsType contacthours = new ContactHour

由于某些原因,我的代码不起作用,它可能位于从到部分的
contacthours.hours1和
contacthours1上

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;
第一个问题是您没有使用24小时格式字符串:

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

这是否是唯一的问题还不清楚。

你说的“工作不正常”是什么意思?你面临的问题是什么?预期的行为是什么?我们无法猜测“不工作”意味着什么。简单的解决方案-使用调试器,进入代码,检查
contacthours.Hours1From
contacthours.hours2 from
的值,并确保它们可以作为
DateTime
进行分析。这很可能比等待别人抓住他们的水晶球要快……至少有一个问题可能来自这样一个事实,即您使用的是24小时日期时间
16:00
,应该解析为
HH:mm
。我修复了HH:mm,但不起作用。。因此,我显然在使用易趣APi,并且我能够正常发布,但是当我添加此代码时,什么都没有发生。根据易趣,这是get Function:private System.DateTime mHours1From;[System.Xml.Serialization.xmlementAttribute(DataType=“time”)]public System.DateTime Hours1From{get{return this.mHours1From;}set{this.mHours1From=value;this.mHours1FromSpecified=true;}所以我真的应该使用parseexact吗?我很困惑-您是从API获取时间还是发送时间?你真的很难对时间进行编码,还是它们来自API?不,我用这个发送时间,我试图向你展示设置函数Hours1From的源代码,以确保使用我的parseexact函数设置它是否合适。从需要
DateTime
的角度来看,是的。不过,不清楚API对
日期时间的日期部分做了什么。是的,这就是我试图解释的问题。。我不确定我发送的格式是否正确。。