I have the need of parsing a date that looks like this:
"2018-03-08T17:37:09.2694781-00:00"
Notice the fractional seconds, I need to keep all 7 digits because then I need to send back to my server exactly the same date. So, I need to be able to convert that string to Date, do some stuff and then send it back to another server thus converting that Date back to String again and keeping the same format and fractional seconds, keeping the original date as String is not an option here.
I already tried this but it does not work because the original Date/Time gets modified for some unknown reason
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.Axxx"
let dateObj = formatter.date(from:("2018-03-08T17:37:09.2694781-00:00"))
//This produces: "2018-03-08 00:44:54 UTC", nothing to do with the original date, it would be fine if converted to UTC, though
I also tried a formatter like
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZZZZZ"
But that truncates my fractional seconds to 3 digits.