0

I am having a Date String in this format "2012-09-06 04:57:00.000". I need to separate the time in that string in 04:57AM like that. help me out of this ?

Gowtham
  • 327
  • 8
  • 17

1 Answers1

3
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm:ss a"];
NSString *timeStr =  [formatter stringFromDate:[NSDate date]];

The above code is with ARC otherwise you need to release formatter like

formatter release
msk
  • 8,885
  • 6
  • 41
  • 72
  • thanks.. how can i proceed for any date? i'm having previous date along with time. so i that case how can i retrieve from that date string – Gowtham Sep 06 '12 at 10:37
  • If you want to start from Date string you can use NSString methods (parsing or like [this](http://stackoverflow.com/questions/3432260/how-can-i-convert-a-nsstring-representation-of-a-time-value-into-two-nsintegers) or you can convert your NSString date to NSDate first. How ? see [this](http://stackoverflow.com/questions/1353081/nsstring-to-nsdate) – msk Sep 06 '12 at 10:46