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

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