Swift Cheat Sheet for Dates, Formatters, & Date Components

Working with NSDate, NSDateFormatter, and NSDateComponents can be a little convoluted, so I’ve created myself a cheat sheet that will be updated as I discover new tips and tricks in this realm.

The new cheat sheet can be found over at GitHub in the form of an Xcode Playground:

Topics that are included in the Playground are as follows:

  • Getting today’s date
  • Converting NSDate to String
  • Converting String to NSDate
  • Getting components of an NSDate
  • Setting components of an NSDate
  • Creating new NSDate instances from NSDateComponent instances

The best way to view this cheat sheet is by downloading the playground from GitHub, but here’s a straight copy-paste from the repo in case you just want to copy and paste it into a playground of your own from here: