Search code examples
ioscocoaios4xcode4

How do I enter the time value in hh:mm:ss format?


I need to enter the time value hh:mm:ss (09:45:56) format , but in the Xcode text field I always get (094556) as format -
how to resolve this?


Solution

  • You can use NSDateFormatter to parse any custom format

    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    
    dateformatter.dateFormat = @"HH':'mm':'ss";
    
    NSString *mydate = @"09:45:56" 
    
    NSDate *parseddate = [dateformatter dateFromString:mydate];
    

    This should give you a date of "9.45 am today"

    The Docs for NSDateFormatter are pretty good but you can find the specific formatter variants possible here. Its linked from the apple docs.

    http://www.unicode.org/reports/tr35/tr35-19.html#Date_Format_Patterns