Skip to content

Instantly share code, notes, and snippets.

@alex-zige
Last active January 1, 2016 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-zige/8216563 to your computer and use it in GitHub Desktop.
Save alex-zige/8216563 to your computer and use it in GitHub Desktop.
Rails standard time to object-c NSdate or vice versa
//Rails time to NSdate
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZ"];
NSDate *date = [df dateFromString:@"2013-04-07T21:19:14Z"];
//NSDate to String
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy HH:mm a"];
//Optionally for time zone converstions
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Pacific/Auckland"]];
NSString *meeting_date = [formatter stringFromDate:meeting.meeting_date];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment