1

How can I generate (iOS 7) ISO 8601 datetimes like Y-m-d\TH:i:s\Z in PHP?


PHP Code:

gmdate('Y-m-d\TH:i:s\Z'); // Output: 2014-02-12T12:08:43Z

Objective-C: (Looking around the web I found this code, but its not returning exactly ISO 8601)

- (NSString *)timestampISO8601 // Output: 2014-02-12T10:12:19-02:00
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
    NSDate *date = [NSDate date];

    return [dateFormatter stringFromDate:date];
}
Luciano Nascimento
  • 2,600
  • 2
  • 44
  • 80

1 Answers1

2

Try this:

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];

Is what I use and it works.

Antonio MG
  • 20,382
  • 3
  • 43
  • 62