小笔记
var dateFormatter = NSDateFormatter();
dateFormatter.dateFormat = ""; //时间格式,参考 :"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
于是就可以:
dateFormatter.stringFromDate( NSDate 的值,比如 datePicker.date )
简易方法:
XML/HTML代码
- func dateformatterDate(date: NSDate) -> NSString
- {
- var dateFormatter: NSDateFormatterNSDateFormatter = NSDateFormatter()
- dateFormatter.dateFormat = "MM-dd-yyyy"
- dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
- return dateFormatter.stringFromDate(date)
- }
- //--- Convert Date String to NSDate ---//
- func dateformatterDateString(dateString: NSString) -> NSDate?
- {
- var dateFormatter: NSDateFormatterNSDateFormatter = NSDateFormatter()
- dateFormatter.dateFormat = "MM-dd-yyyy"
- dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
- return dateFormatter.dateFromString(dateString)
- }