0

I'm trying to parse this date : 2016-04-16T10:00:00-0400 but I don't know what is '-0400' in this case ?

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss<?>"];
                                                 ^^^
NSDate *date = [dateFormat dateFromString:@"2016-04-16T10:00:00-0400"];

Thanks for your help !

Thlbaut
  • 649
  • 7
  • 25

2 Answers2

1

use

   NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
//[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSDate *date = [dateFormat dateFromString:@"2016-04-16T10:00:00-0400"];
NSLog(@"date ==%@",date);
 [dateFormat setDateFormat:@"yyyy"];
NSString *finalStr = [dateFormat stringFromDate:date];
NSLog(@"finalStr ==%@",finalStr);

output like

enter image description here

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

Thanks to @gnasher729 for the tip, here is the Date Field Symbol Table : http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns

The answer is for the date 2016-04-16T10:00:00-0400 is :

[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
Thlbaut
  • 649
  • 7
  • 25