Add minutes to my existing date iOS swift

  Problem:

I had one date with me.I want to add some minutes to the date and get the new date.

Solution:

extension Date {

    func addminutes(minsToAdd: Int) -> Date {

        let secondsInHours: TimeInterval = Double(minsToAdd) * 60

        let dateWithHoursAdded: Date = self.addingTimeInterval(secondsInHours)

        //Return Result

        return dateWithHoursAdded

    }}



Call the above function as like below.


let newDate = yourdate.addminutes(10)



newDate will store the new date after appending 10 minutes.

Comments

Popular posts from this blog

store cgpoint in userdefaults iOS swift

libc++abi: terminating due to uncaught exception of type NSException iOS swift