Skip to content

Instantly share code, notes, and snippets.

@johnantoni
Created July 25, 2016 17:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save johnantoni/12f665c55eb05df3ea651cf76881ab4c to your computer and use it in GitHub Desktop.
Swift ~ format NSDate to String
//: Playground - noun: a place where people can play
import Foundation
import Cocoa
extension NSDate {
func toS(let format:String) -> String? {
let formatter:NSDateFormatter = NSDateFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
formatter.timeZone = NSTimeZone()
formatter.dateFormat = format
return formatter.stringFromDate(self)
}
}
var today = NSDate().toS("dd MMMM YYYY")
@johnantoni
Copy link
Author

johnantoni commented Jul 25, 2016

returns "25 July 2016"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment