Search code examples
c#asp.netebay-api

DateTime ParseExact throwing exception with hh vs HH


contacthours.Hours1From and contacthours.Hours1To are throwing an exception. is there a difference between hh and HH ?

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;

Solution

  • The first problem is that you're not using the 24-hr hour format string:

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

    Whether or not that's the only problem is unclear.