Dates
For date portability between server and client, and between timezones, it is best to store times and dates in UTC (GMT +0) and then convert them to the user timezone for displaying.
Dates should be formatted in ISO 8601 2014-10-04T23:23:23.000Z
Objective-C
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
// NSDate from NSString
NSDate *date = [dateFormatter dateFromString:"2014-10-04T23:23:23.000Z"];
// NSString from NSDate
NSString *string = [dateFormatter stringFromDate:date];Swift
let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier:"en_US_POSIX")
dateFormatter.timeZone = NSTimeZone(name:"UTC")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
// NSDate from NSString
if let date = dateFormatter.dateFromString("2014-10-04T23:23:23.000Z") {
// String from NSDate
let string = dateFormatter.stringFromDate(date)
}Ruby
# String from Time
string = Time.now.utc.iso8601
# Time from String
time = Time.iso8601("2014-10-04T23:23:23.000Z")Javascript
var date = new Date();
// String from Date
var string = date.toISOString();
// Date from String
date = Date.parse("2014-10-04T23:23:23.000Z")Java
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
Date date = format.parse(string);
String string = formatter.format(date);