Skip to content

Instantly share code, notes, and snippets.

@wurmr
Created November 6, 2015 20:08
Show Gist options
  • Save wurmr/5102ffb8a763fd4c36d1 to your computer and use it in GitHub Desktop.
Save wurmr/5102ffb8a763fd4c36d1 to your computer and use it in GitHub Desktop.
iOS Date Bug
//: 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!))
@wurmr
Copy link
Author

wurmr commented Nov 6, 2015

Bug? Or Feature. the fix is to use yyyy-MM-dd as a format string, this will display the correct calendar year.

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