How to construct formatter(NSFormatter) for following Date string
Date dateString = \"Sun Oct 30 2016 00:00:00 GMT+0530 (IST)\"
let dateFormatter = DateFormatte
I think you'll have to tell DateFormatter
to ignore the 'GMT' part, because that throws it off. GMT is implied if you have +0530
though, so you don't need it.
For this string:
let dateString = "Sun Oct 30 2016 00:00:00 GMT+0530"
This format works:
dateFormatter.dateFormat = "E MMM d yyyy HH:mm:ss 'GMT'x"
If the (IST)
is always the same, you can tell the date formatter to ignore it too by using
dateFormatter.dateFormat = "E MMM d yyyy HH:mm:ss 'GMT'x '(IST)'"
If that part can vary, you should probably use String methods to remove that part of the string before parsing the date.