Created
November 6, 2015 20:08
-
-
Save wurmr/5102ffb8a763fd4c36d1 to your computer and use it in GitHub Desktop.
iOS Date Bug
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 UIKit | |
let components = NSDateComponents() | |
components.year = 2015 | |
components.month = 12 | |
components.day = 28 | |
let date = NSCalendar.currentCalendar().dateFromComponents(components) | |
print(date) | |
let formatter = NSDateFormatter() | |
// YYYY-MM-dd -> 2015-07-04 | |
formatter.dateFormat = "YYYY-MM-dd" | |
print(formatter.stringFromDate(date!)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug? Or Feature. the fix is to use
yyyy-MM-dd
as a format string, this will display the correct calendar year.