最新的、已测试正确~
let gregorian = Calendar(identifier:Calendar.Identifier.gregorian)
let now = Date()
let components = gregorian.dateComponents([.year], from: now, to: now)
let age = components.year
let gregorian = Calendar(identifier:Calendar.Identifier.gregorian)
let now = Date()
let components = gregorian.dateComponents([.year], from: now, to: now)
let age = components.year
2017-04-06
我的方法哈,取出其中的年份信息并转化为整型 :
@IBAction func okTapped(_ sender: Any) {
let date = birthday.date
let dformatter = DateFormatter()
dformatter.dateFormat = "yyyy"
let datesr = dformatter.string(from: date)
let year = Int(datesr)!
}
代码第4行使用MM输出月份,dd输出日期。。
@IBAction func okTapped(_ sender: Any) {
let date = birthday.date
let dformatter = DateFormatter()
dformatter.dateFormat = "yyyy"
let datesr = dformatter.string(from: date)
let year = Int(datesr)!
}
代码第4行使用MM输出月份,dd输出日期。。
2017-04-05
我的方法,输出自定义的格式:
@IBAction func okTapped(_ sender: Any) {
let date = birthday.date
let dformatter = DateFormatter()
dformatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss"
let datesr = dformatter.string(from: date)
Result.text = "\(datesr)"
}
@IBAction func okTapped(_ sender: Any) {
let date = birthday.date
let dformatter = DateFormatter()
dformatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss"
let datesr = dformatter.string(from: date)
Result.text = "\(datesr)"
}
2017-04-05
我没有设置sender as UISlider,也成功了,直接调用控件函数HeightNumber的Value。代码如下:
@IBAction func NumberChanged(_ sender: Any) {
var i = Int(HeightNumber.value)
Height.text = "\(i)厘米"
}
我想问老师那样处理有什么别的目的或者好处吗?求教~~
@IBAction func NumberChanged(_ sender: Any) {
var i = Int(HeightNumber.value)
Height.text = "\(i)厘米"
}
我想问老师那样处理有什么别的目的或者好处吗?求教~~
2017-04-01
swift3 报错 unrecognized selector sent to instance
2017-02-10