What would be the best algorithm / code to convert time to float? I'm doing this in Obj-c but really all I need is an algorithm and I can make the code from there.
EX:
EDIT: My time format is minutes since midnight.
You can parse the string to get two int numbers and an am/pm part (h, m, and a), and then calculate the fraction as follows:
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 time within a single day, use NSDateFormatter with an "A" date format to produce milliseconds since midnight, then mash on that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With