What would be the best algorithm / code to convert time to float? I am doing this in Obj-c, but actually all I need is an algorithm and I can make code from there.
Example:
EDIT: My time format is minutes since midnight.
You can parse the string to get two digits int and the am/pm ( h , m and a ) part, and then calculate the fraction like this:
int
am/pm
h
m
a
int h, m, a; // set a to 0 for "am", or 1 for "pm" float time = 60*(a*12+h)+m; float res = time / 60.0;
How about NSDate timeIntervalSinceDate? And divide by 3600, of course.
Or, for a time in one day, use an NSDateFormatter with the "A" date format to produce milliseconds since midnight and then slow down.