let locale=NSLocale.current
let dateFormat=DateFormatter.dateFormat(fromTemplate: "yyyy-MM-dd", options: 0, locale: locale)
let dateFormater=DateFormatter()
dateFormater.dateFormat=dateFormat
date.text=dateFormater.string(from: todo.date as Date)
let dateFormat=DateFormatter.dateFormat(fromTemplate: "yyyy-MM-dd", options: 0, locale: locale)
let dateFormater=DateFormatter()
dateFormater.dateFormat=dateFormat
date.text=dateFormater.string(from: todo.date as Date)
2017-05-12
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell=self.tableview.dequeueReusableCell(withIdentifier: "todocell")
let todo=Todos[indexPath.row] as TodoModel
let cell=self.tableview.dequeueReusableCell(withIdentifier: "todocell")
let todo=Todos[indexPath.row] as TodoModel
2017-05-12
class TodoViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Todos=[TodoModel(id:"1",image:"aaa.png",title:"去游乐场",date:dateFromString(dateStr:"2014-11-02")!)]
}
}
override func viewDidLoad() {
super.viewDidLoad()
Todos=[TodoModel(id:"1",image:"aaa.png",title:"去游乐场",date:dateFromString(dateStr:"2014-11-02")!)]
}
}
2017-05-12
import UIKit
var Todos:[TodoModel]=[]
func dateFromString(dateStr:String)->NSDate?{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let date = dateFormatter.date(from: dateStr)
return date as NSDate?
}
var Todos:[TodoModel]=[]
func dateFromString(dateStr:String)->NSDate?{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let date = dateFormatter.date(from: dateStr)
return date as NSDate?
}
2017-05-12
我 adding missing constraints 是灰的 点不了,我点的 reset to suggested constraints ~
2017-04-19
最新的、已测试正确~
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