Formatting date with Swift

后端 未结 2 1650
无人共我
无人共我 2021-01-23 04:09

I am trying to Convert a String into Date using Date Formatter .

var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = \"yyyy-MM-dd’T’HH:mm:ss’Z’\"
va         


        
2条回答
  •  野的像风
    2021-01-23 04:35

    Try like this:

    let dateFormatter = NSDateFormatter()
    dateFormatter.calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
    dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
    dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
    let availabletoDateTime = dateFormatter.dateFromString("2015-07-16T08:00:00Z")
    

提交回复
热议问题