Last active
November 11, 2016 13:50
-
-
Save MLKrisJohnson/dca6b8d974ecb92e36c946af96a88de5 to your computer and use it in GitHub Desktop.
Example of using NSDateFormatter to get/parse month names for user's locale/calendar.
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
import Foundation | |
let dateFormatter = DateFormatter() | |
let calendar = dateFormatter.calendar! | |
dateFormatter.dateFormat = "MMMM" | |
let now = Date() | |
let nowAsString = dateFormatter.string(from: now) // "November" | |
let september = dateFormatter.date(from: "September")! | |
let monthNumber = calendar.component(Calendar.Component.month, from: september) // 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment