(The previous version of this answer was actually incorrect; it did not correctly handle the time zone.)
According to autonomous JSON serialization :
DateTime values ββare displayed as JSON strings in the form "/ Date (700000 +0500) /", where the first number (700000 in the above example) is the number of milliseconds in the GMT time zone, normal (without daylight saving time)) midnight January 1, 1970. The number may be negative to represent earlier times. The part that consists of "+0500" in the example is optional and indicates that the time is local, that is, it must be converted to a local time zone during deserialization. If it is absent, the time is deserialized as Utc. The actual number (in this example, β0500β) and its sign (+ or -) are ignored.
and use JSON.NET to parse the date in json format. Date (epochTime-offset)
... In this [screw format] [1], the timestamp part is still based solely on UTC. Offset is additional information. This does not change the time stamp. You can specify another offset or completely omit it, and it will remain at that moment in time.
the first number in \/Date(1440156888750-0700)\/ is the number of milliseconds that have passed since the "era" of January 1, 1970 GMT, and the -0700 part of the time zone -0700 simply ignored.
Here is a Swift 5 extension method for Date that validates the string using a regular expression (accepting as \/Date(...)\/ and /Date(...)/ , with /Date(...)/ or without time zone) and converts the specified number of milliseconds to Date :
extension Date { init?(jsonDate: String) { let pattern = #"\\?/Date\((\d+)([+-]\d{4})?\)\\?/"# let regex = try! NSRegularExpression(pattern: pattern) guard let match = regex.firstMatch(in: jsonDate, range: NSRange(jsonDate.startIndex..., in: jsonDate)) else { return nil }
Example:
let jsonDate = "\\/Date(1440156888750-0700)\\/" print("JSON Date:", jsonDate) if let theDate = Date(jsonDate: jsonDate) { print("Date:", theDate) } else { print("wrong format") }
Output:
JSON Date: \ / Date (1440156888750-0700) \ /
Date: 2015-08-21 11:34:48 +0000
(Versions for Swift 3 and Swift 4 can be found in the editing history.)