【发布时间】:2015-02-18 16:00:09
【问题描述】:
我有一个需要验证的 UIDatePicker。我想检查 UIDatePicker 中的工作日是否是特定的 int 值。
我用
@IBAction func validateDateTime(sender: AnyObject) {
var date = self.dateTime.date
let formatterWeekday = NSDateFormatter()
formatterWeekday.dateFormat = "e"
let weekday_string = formatterWeekday.stringFromDate(date)
}
要获得工作日,但如何将其转换为 int 以便与其他 int 值进行比较?我试过了:
weekday_string.intValue()
但似乎是weekday_string不支持intValue方法。
【问题讨论】:
-
我也试过了,但我不知道如何快速编写这段代码。我对使用 os 进行编码非常陌生...
-
Jerome 的回答告诉你如何用 swift 写这个。
标签: swift nsdate nsdateformatter