Bạn đặt chế độ dateFormat (hoặc dateStyle).
Dưới đây là một ví dụ hoàn chỉnh để phân tích nó nhằm giúp bạn dễ dàng thấy những gì bạn đang bỏ lỡ.
Dòng cụ thể mà bạn muốn chú ý là nơi bạn cần đặt dateFormat của dateFormatter. Ở đây, chúng tôi sẽ đặt nó thành "yyyy-MM-dd" sẽ cung cấp kết quả như "2014-06-22".
func formatADate() {
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let d = NSDate()
let s = dateFormatter.stringFromDate(d)
println(s)
}
Sau đó, bạn có thể gọi formatADate().
Khám phá NSDateFormatter reference để biết thêm thông tin.
đọc [Chuỗi Interpolation] (https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_language/StringsAndCharacters.html) tham khảo – Mohsen