Created
July 25, 2016 17:51
-
-
Save johnantoni/12f665c55eb05df3ea651cf76881ab4c to your computer and use it in GitHub Desktop.
Swift ~ format NSDate to String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
returns "25 July 2016"