Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hijri (islamic) calendar in swift التاريخ الهجري

Tags:

ios

swift

hijri

can someone help me please

I'm trying to create an IOS app using Swift language and I need to use Hijri (islamic) calendar

I tried many time but I failed :(

this is my try

    let datenow = NSDate()
    let calendar = NSCalendar.currentCalendar()
    let components = calendar.components(NSCalendarUnit(UInt.max), fromDate: datenow)

    var gregorian = NSCalendar(identifier:NSIslamicCivilCalendar)
    var date = gregorian.dateFromComponents(components)

    println(date)

and the output is wrong

   2576-04-25 09:05:08 +0000

We are in year 1434 in hijri not 2576 !

like image 567
Abdulaziz Noor Avatar asked Sep 25 '14 09:09

Abdulaziz Noor


1 Answers

Swift 5:

let hijriCalendar = Calendar(identifier: .islamicCivil)

let formatter = DateFormatter()
formatter.locale = Locale(identifier: "ar")
formatter.calendar = hijriCalendar
formatter.dateFormat = "dd/MM/yyyy"

print(formatter.string(from: Date()))
like image 166
shbedev Avatar answered Oct 18 '22 13:10

shbedev