How to find weekday from today's date using NSDate?

后端 未结 5 2012
春和景丽
春和景丽 2020-12-05 07:13

I know that I can figure out today\'s date by [NSDate date]; but how would I find out today day of the week, like Saturday, Friday etc.

I know that

5条回答
  •  醉梦人生
    2020-12-05 07:30

    If someone is interested in a Swift solution, then use:

    import Foundation
    
    let weekday = NSCalendar.current.component(.weekday, from: Date())
    print(weekday) // => prints the weekday number 1-7 (Sunday through Saturday) 
    

    See the demo.

    Update: fixed to work in Swift 3

提交回复
热议问题