NSDatecannot be represented in JSON natively. As the documentation says NSJSONSerialization:
An object that can be converted to JSON must have the following properties:
The top level object is NSArrayor NSDictionary.
NSString, NSNumber, NSArray, NSDictionary NSNull.
NSString.
NaN .
, , JSON. - (, ISO 8601/RFC 3339, 2016-01-25T06:54:00Z).
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
, macOS 10.12 iOS 10 :
NSISO8601DateFormatter *formatter = [[NSISO8601DateFormatter alloc] init];
:
NSString *birthDateString = [formatter stringFromDate:birthDate];
. Apple Technical Q & A 1480.
, , , yyyy-MM-dd.
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
formatter.dateFormat = @"yyyy-MM-dd";
NSString *birthDateString = [formatter stringFromDate:birthDate];
, , - , .