//Accepts String to convert Simple Input Format hh:mm:ss to Time Object, Throws Application Exception for wrong format public Time SetInput(String time) { string[] timeValues = time.Split(new string[] { ":" }, StringSplitOptions.None); Time t = new Time(); t.setHours(Int32.Parse(timeValues[0])); t.setMinutes(Int32.Parse(timeValues[1])); t.setSeconds(Int32.Parse(timeValues[2])); return(t); }
//Split the time to hours,minutes and Seconds private Time SetTime(String sTime) { Time time = new Time(); string[] timeValues = sTime.Split(new string[] { ":" }, StringSplitOptions.None); time.setHours(Int32.Parse(timeValues[0])); time.setMinutes(Int32.Parse(timeValues[1])); time.setSeconds(Int32.Parse(timeValues[2])); return(time); }
public static Time convertFromString(string aTime) { try { var time = new Time(); var splittedTime = aTime.Split(':'); time.setSeconds(int.Parse(splittedTime[2])); time.setMinutes(int.Parse(splittedTime[1])); time.setHours(int.Parse(splittedTime[0])); return(time); } catch (Exception ex) { throw new InvalidFormatException(String.Format("Please enter a valid time. Exception: {0}", ex.Message)); } }