-1

I am trying to get date from this string 2014-10-08T15:09:19+05:30. My code is

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:sszzz"];
NSLog(@"%@",[dateFormatter dateFromString:@"2014-10-08T15:09:19+05:30"]);

but o/p is 2014-10-08 09:39:19 +0000

expected is 2014-10-08 15:09 PM

saw other threads also and tried with timezone as suggested in others but not able to get the correct date.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2017285
  • 283
  • 1
  • 2
  • 10
  • 1
    Why do you expect `2014-10-08 15:09 PM`? That's not the format used by the `NSDate description` method. – rmaddy Oct 15 '14 at 07:13
  • 1
    You **do** have the correct date. Those two dates are the same since I assume you live in India. – borrrden Oct 15 '14 at 07:26
  • [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm a"]; someone just answered with that i came to know. thank u. – user2017285 Oct 15 '14 at 07:29
  • yes @borrrden by just seeing that time i was thinking that's wrong. now i got it. thanks anyways. – user2017285 Oct 15 '14 at 07:33
  • Duplicate of [Getting date from \[NSDate date\] off by a few hiurs](http://stackoverflow.com/questions/8466744/getting-date-from-nsdate-date-off-by-a-few-hours) – jscs Oct 15 '14 at 07:34

1 Answers1

2

The issue is that your code is equivalent to:

NSDate *date = [dateFormatter dateFromString:@"2014-10-08T15:09:19+05:30"];
NSLog(@"%@", [date description]);
//                 ^^^^^^^^^^^

and [NSDate description] generates a string in the GMT timezone, which leads to your confusion.

Droppy
  • 9,691
  • 1
  • 20
  • 27