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

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift