I have two times both in String format:
timeOne = "12:58 AM"
timeTwo = "1:05 PM"
I convert them into NSDate like this
func convertTime(tim: String) -> NSDate{
let strDate = tim
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "HH:mm a"
//converts into NSDate so we can find the time remaining
return (dateFormatter.dateFromString(strDate))!
}
let tOne = convertTime(timeOne)
let tTwo = convertTime(timeTwo)
converting tOne and tTwo outputs me
tOne = 2000-01-01 00:58:00 +0000
tTwo = 2000-01-01 12:05:00 +0000
I compare the two times but i want it to return 7 mins whereas im getting '667' The code to compare is:
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.Minute, fromDate: tOne, toDate: tTwo, options: [])
print(components)
This prints out
667
However it works if the both times are the same AM or PM What i mean by this is that lets say
tOne = "1:06 PM"
tTwo = "1:15 PM"
running the comparison code it successfully outputs "9"