My property dob
of Patient
object is String
and currently storing 12-Jan-2017
and I want to convert it to French locale such as 12-Janv.-2017
.
Below are my steps:
Converting 12-Jan-2017
into 1954-09-07 04:00:00 UTC
let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale.init(localeIdentifier: "en_US_POSIX")
dateFormatter.dateFormat = "dd-MMM-yyyy"
let date = dateFormatter.dateFromString("12-Jan-2017") // now date is 1954-09-07 04:00:00 UTC
Next I have to set the locale
of dateFormatter
to fr
dateFormatter.locale = NSLocale.init(localeIdentifier: "fr")
let frenchDate = dateFormatter.stringFromDate(date!) // now it is 12-Janv.-2017
I dont think it is the best way to do a conversion. Are there any other efficient way for it. Any comments are welcomed.