0

IST timezone is not recognised by NSDateFormatter. Following date is recognised

let dateString = "Jun 10, 2015 @ 12.30 AM PDT"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a-zzz"
let date = dateFormatter.dateFromString(dateString)

but time with IST timezone is not recognised.

let dateString = "Jun 10, 2015 @ 12.30 AM IST"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a-zzz"
let date = dateFormatter.dateFromString(dateString)

Date is nil for IST timezone.

Deekshith Bellare
  • 725
  • 2
  • 6
  • 19

1 Answers1

0

As a workaround this helps:

let dateString = "Jun 10, 2015 @ 12.30 AM"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a"
dateFormatter.timeZone = NSTimeZone(abbreviation: "IST")
let date = dateFormatter.dateFromString(dateString)
Thulur
  • 358
  • 1
  • 4
  • 11
  • Date is received from server. timezone can be anything. we can't hardcode – Deekshith Bellare Apr 24 '15 at 12:25
  • Take a look at http://stackoverflow.com/questions/9084980/nsdateformatter-doesnt-show-time-zone-abbreviation-for-asia-kolkata-for-the the special case is solved by: dateFormatter.locale = NSLocale(localeIdentifier: "en_IN") – Thulur Apr 24 '15 at 12:46