I am currently reading an assortment of data from a text file and parsing everything. One of the shared elements is the time the event started in the format:
yyMMddHHmm 1306050232
Then I parse the following:
string year = "20" + time[0].ToString() + time[1].ToString(); string month = time[2].ToString() + time[3].ToString(); string day = time[4].ToString() + time[5].ToString(); string hour = time[6].ToString() + time[7].ToString(); string minute = time[8].ToString() + time[9].ToString(); string ampm =""; int hourInt = Convert.ToInt32(hour); if (hourInt <= 12) { time = month + "." + day + "." + year + "@" + hour + ":" + minute + " " + "AM"; ampm= "AM"; } else { hourInt = hourInt - 12; time = month + "." + day + "." + year + "@" + hourInt.ToString() + ":" + minute + " " + "PM"; ampm= "PM"; }
once they figured out, I combined the variables and try to put them in a DateTime.
string tempStartTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + " " + ampm; string starttime = DateTime.ParseExact(tempStartTime, "yyyy-MM-dd HH:mm tt",null);
My problem: I get a warning like this from try catch:
System.FormatException: String was not recognized as a valid DateTime. at System.DateTime.ParseExact(String s, String format, IFormatProvider provider) at Project.GUI.parseSchedule(Int32 count)
I donβt understand why, or how to do it right.
All I want to do is take the start time from the file, convert it to a datetime object, and then continue.
source share