I want to convert data between "Persian date and Gregorian" in swift. I was looking into algorithm to help me convert between them, but I did not really understand how to implement them.
If their is an existing way to do the job in Swift please point me to it.
Providing and example will be also appreciated.
For Swift 5: Format is little change for year
let formatter = DateFormatter()
formatter.dateFormat = "dd/MM/YYYY"
formatter.calendar = Calendar(identifier: .gregorian)
let date = Date()
let dateInGrogrian = formatter.string(from: date)
print(dateInGrogrian)
formatter.calendar = Calendar(identifier: .persian)
formatter.dateFormat = "dd/MM/YYYY"
print("Converted date to Hijri = \(formatter.string(from: date))")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With