Skip to content

Instantly share code, notes, and snippets.

@SlaunchaMan
Created August 8, 2014 19:07
Show Gist options
  • Select an option

  • Save SlaunchaMan/550b19c83cdb0e0802db to your computer and use it in GitHub Desktop.

Select an option

Save SlaunchaMan/550b19c83cdb0e0802db to your computer and use it in GitHub Desktop.
New Formatters in iOS 8
import UIKit
var componentsFormatter = NSDateComponentsFormatter()
componentsFormatter.unitsStyle = .Abbreviated
var components = NSDateComponents()
components.hour = 1
components.day = 5
components.year = 1
var formattedComponents = componentsFormatter.stringFromDateComponents(components)
var intervalFormatter = NSDateIntervalFormatter()
intervalFormatter.dateStyle = .NoStyle
intervalFormatter.timeStyle = .ShortStyle
var currentDate = NSDate()
var future = currentDate.dateByAddingTimeInterval(10_000)
var formattedInterval = intervalFormatter.stringFromDate(currentDate, toDate: future)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment