tags:

views:

183

answers:

2

I am getting some open/closed times as integers since midnight. For example:

"1140" = 19:00 (or 7 pm if you will) or; "570" = 9:30 (or 9.30 am)

I can easily get the time in European format, just by doing doing a simple calculation and formatting:

[NSString stringWithFormat:@"%d:00", (T / 60)]

However, this doesn't work for half hours, such as "570 minutes since midnight". Also, I run into problems if I want to include a bit of localization, because some people may prefer AM/PM times.

Does NSDate include a method for easily implementing times using the above? Or can anyone tell me how I would at least convert a time like "570 minutes since midnight" to 9:30 properly. Right now it obviously won't write the :30 part.

Thank you

+2  A: 

The simple answer could be to just compute the hours and minutes separately:

hours = T / 60;
mins = T % 60;

When it comes to displaying of time and converting this to a NSString you should let the NSDateFormatter do all the dirty work for you.

Claus

Claus Broch
+1  A: 

You have your own answer:

[NSString stringWithFormat:@"%d:%d", (T / 60), (T % 60)] 
Paulo Santos
And thanks to you too!
Canada Dev