Skip to content

Instantly share code, notes, and snippets.

@codingrhythm
Created February 11, 2013 01:30
Show Gist options
  • Save codingrhythm/4751879 to your computer and use it in GitHub Desktop.
Save codingrhythm/4751879 to your computer and use it in GitHub Desktop.
Objective-C class that converts standard ISO date string to NSDate object
//
// NSDate+ISOSupport.h
//
// Created by Zhu Yuzhou on 1/12/13.
//
#import <Foundation/Foundation.h>
@interface NSDate (ISOSupport)
+(NSDate *)dateWithISOString:(NSString *)dateString;
@end
//
// NSDate+ISOSupport.m
//
// Created by Zhu Yuzhou on 1/12/13.
//
#import "NSDate+ISOSupport.h"
@implementation NSDate (ISOSupport)
+(NSDate *)dateWithISOString:(NSString *)dateString
{
dateString = [dateString stringByReplacingOccurrencesOfString:@":" withString:@""];
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd'T'HHmmss.SSSSSSZZ"];
return [f dateFromString:dateString];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment