Get time with AM and PM from date iOS swift

Problem: 

I had a date with me and i want to get the time only from the date.How to achieve that?

Solution:

extension Date {

    func getTime() -> String {

        let format = DateFormatter()

        format.timeZone = NSTimeZone.local

        format.dateFormat = "hh:mm a"

        return format.string(from: date)

    }

}


Call the above function as like below


myDate.getTime()

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift