Get Weekday from Date - Swift 3

后端 未结 6 969
时光说笑
时光说笑 2021-01-01 08:21

I have looked around a bit, but didnt find a quick answer for this in swift 3. I get todays weekday like this:

let weekday = Calendar.current.component(.week         


        
6条回答
  •  天涯浪人
    2021-01-01 09:02

    If you want dayNumber component in TimeZone

    func dayNumberOfWeek() -> Int? {
        let timeZone = TimeZone(abbreviation: "EDT")
        let component =  Calendar.current.dateComponents(in: timeZone!, from: self)
        return  component.day
    }
    

提交回复
热议问题