DateFormatter
不能处理这个。用于NSRegularExpression
分离组件:
let str = "/Date(1488335133000+0100)/"
let regex = try! NSRegularExpression(pattern: "/Date\\((\\d+)(\\+|-)(\\d{2})(\\d{2})\\)/", options: [])
if let match = regex.firstMatch(in: str, options: [], range: NSMakeRange(0, str.characters.count)) {
let nsstr = str as NSString
let millisecond = Double(nsstr.substring(with: match.rangeAt(1)))!
let sign = nsstr.substring(with: match.rangeAt(2))
let hour = Double(nsstr.substring(with: match.rangeAt(3)))!
let minute = Double(nsstr.substring(with: match.rangeAt(4)))!
let offset = (sign == "+" ? 1 : -1) * (hour * 3600.0 + minute * 60.0)
let date = Date(timeIntervalSince1970: millisecond / 1000 + offset)
print(date)
}