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

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift

Parse the value from string value iOS swift