-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
  • 307,833
  • 40
  • 508
  • 550
TruMan1
  • 30,176
  • 50
  • 162
  • 301

1 Answers1

1

Just add the following line

formatter.calendar = calendar
Marius Fanu
  • 6,379
  • 1
  • 16
  • 19