我想创建两个变量-一个变量是星期几(星期一-星期日),另一个变量是当前时间。我要做的不只是在标签中显示它,而是现在尝试一下。
我尝试过,但是我的应用程序崩溃了:
let weekDay = NSCalendar.current.component(.weekday, from: Date())
self.weekDayLabel.text = "\(weekDay)"
答案 0 :(得分:0)
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "EEEE"
let dayInWeek = formatter.string(from: date)