I have data that contains a date string.
Normally it would be in a 'Jan. 3, 1966' type format, but because of international differences, it may not always be exactly that.
I need to read the data in and convert it into a standard date string ('YYYY-MM-DD').
Basically this is what I have so far:
var dataString = 'Jan. 3, 1966'
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = # I DON'T KNOW THE EXACT INPUT FORMAT !
let dateValue = dateFormatter.dateFromString(dataString)
Tested in swift 4, xcode 9
Test:
print("2018-11-04T23:59:00+00:00".detectDate ?? "")
// 2018-11-04 10:00:00 +0000print("2018/11/4".detectDate ?? "")
// 2018-11-04 10:00:00 +0000Xcode 9 • Swift 4 or Xcode 8.3.2 • Swift 3.1
You can use NSDataDetector as follow:
Testing: