LightNight
LightNight

Reputation: 1625

NSDateFormatter get hour and time

I have string value with date(for ex.: 2012-11-30T12:45:00Z), how can I get value like this: 12:45? Thanks..

Upvotes: 2

Views: 1227

Answers (2)

danh
danh

Reputation: 62676

Date formatter approach looks like this:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm"];
NSString *hhmm = [dateFormatter stringFromDate:theDate];

// release dateFormatter if not using ARC... but use ARC

Upvotes: 4

ilmiacs
ilmiacs

Reputation: 2576

NSString* timeStr = [longDateStr substringWithRange:NSMakeRange(11, 5)];

Upvotes: -2

Related Questions