Converting NSString to NSDate (and back again)

后端 未结 17 2499
-上瘾入骨i
-上瘾入骨i 2020-11-21 23:26

How would I convert an NSString like \"01/02/10\" (meaning 1st February 2010) into an NSDate? And how could I turn the NSDat

17条回答
  •  终归单人心
    2020-11-21 23:59

    The above examples aren't simply written for Swift 3.0+

    Update - Swift 3.0+ - Convert Date To String

    let date = Date() // insert your date data here
    var dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd" // add custom format if you'd like 
    var dateString = dateFormatter.string(from: date)
    

提交回复
热议问题