Get the day of the week from date iOS swift

Problem:

I want to get the day(0,1,2,3...) of the week from the particular date.


Solution:

    func getDayOfWeek(_ today:Date) -> Int? {
        //        let formatter  = DateFormatter()
        let myCalendar = Calendar(identifier: .gregorian)
        let weekDay = myCalendar.component(.weekday, from: today)
        return weekDay
    }



0 means sunday,1 means monday etc

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift