-1

I'm trying to print a human-friendly date that's of a different calendar identifier. I am able to get the date, but when I format it, it outputs back to Gregorian (or the user's current calendar I think).

Here's what I'm trying:

var calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierIslamicCivil)
var flags = NSCalendarUnit(UInt.max)
var components = calendar?.components(flags, fromDate: NSDate())

let formatter = NSDateFormatter()
formatter.dateStyle = NSDateFormatterStyle.LongStyle

let dateString = formatter.stringFromDate(calendar!.dateFromComponents(components!)!)

println(dateString)

This prints: May 8, 2015, but I'm trying to get it to print Rajab 19, 1436. Is this possible?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
TruMan1
  • 33,665
  • 59
  • 184
  • 335

1 Answers1

1

Just add the following line

formatter.calendar = calendar
Marius Fanu
  • 6,589
  • 1
  • 17
  • 19