Skip to content

Instantly share code, notes, and snippets.

Created Feb 23, 2011
What would you like to do?
#include <time.h>
+ (NSDate *)dateFromISO8601String:(NSString *)string {
if (!string) {
return nil;
struct tm tm;
time_t t;
strptime([string cStringUsingEncoding:NSUTF8StringEncoding], "%Y-%m-%dT%H:%M:%S%z", &tm);
tm.tm_isdst = -1;
t = mktime(&tm);
return [NSDate dateWithTimeIntervalSince1970:t + [[NSTimeZone localTimeZone] secondsFromGMT]];
- (NSString *)ISO8601String {
struct tm *timeinfo;
char buffer[80];
time_t rawtime = [self timeIntervalSince1970] - [[NSTimeZone localTimeZone] secondsFromGMT];
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S%z", timeinfo);
return [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
- (NSString *)camelCaseString {
static NSRegularExpression *regex = nil;
if (!regex) {
regex = [[NSRegularExpression alloc] initWithPattern:@"(?:_)(.)" options:0 error:nil];
// Use regex...
return string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment