0

I am using NSDateFormatter to convert a string date to a NSDate.

This works.

                   NSDateFormatter * formatDate = [[NSDateFormatter alloc] init];
                    [formatDate setDateFormat:@"ddMMMyyyy hh:mm:ss a zzz"];
                    dateStr = @"01Jul2019 08:15:00 PM EDT";
                    tempInv.time_of_purchase = [formatDate dateFromString:dateStr];

This does not work and returns nil ???

                   NSDateFormatter * formatDate = [[NSDateFormatter alloc] init];
                    [formatDate setDateFormat:@"ddMMMyyyy hh:mm:ss a zzz"];
                    dateStr = @"01Jul2019 08:15:00 PM IST";
                    tempInv.time_of_purchase = [formatDate dateFromString:dateStr];

only difference is the TIME ZONE. In the 2nd one its IDT. note: it seems PST works fine. EST works fine. but others do not.

can anyone shed some light on this ? and why nil would be getting returned. note: the iphone it is running on is EDT.

RayT
  • 3
  • 2
  • See [these search results](https://stackoverflow.com/search?q=nsdateformatter+IST). `IST` is ambiguous. – rmaddy Jul 01 '19 at 23:15
  • Related: https://stackoverflow.com/questions/29846879/nsdateformatterist-not-recognised?r=SearchResults&s=1|67.1353 and https://stackoverflow.com/questions/9084980/nsdateformatter-doesnt-show-time-zone-abbreviation-for-asia-kolkata-for-the?r=SearchResults&s=3|52.9345 and https://stackoverflow.com/questions/21746798/ist-time-zone-not-getting-parsed?r=SearchResults&s=4|51.9828 and https://stackoverflow.com/questions/13449004/nsdateformatter-geting-null?r=SearchResults&s=5|49.7545 – rmaddy Jul 01 '19 at 23:15
  • It's always best to avoid timezone abbreviations since they are not unique. Use full timezone names or offsets. – rmaddy Jul 01 '19 at 23:19

0 Answers0