Getting the difference between two Dates (months/days/hours/minutes/seconds) in Swift

I am trying to get the difference between the current date as NSDate() and a date from a PHP time(); call for example: NSDate(timeIntervalSinceReferenceDate: 1417147270). How do I go about getting the difference in time between the two dates. I’d like to have a function that compares the two dates and if(seconds > 60) then … Read more

Date Format in Swift

How will I convert this datetime from the date? From this: 2016-02-29 12:24:26 to: Feb 29, 2016 So far, this is my code and it returns a nil value: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = “MM-dd-yyyy” dateFormatter.timeZone = NSTimeZone(name: “UTC”) let date: NSDate? = dateFormatter.dateFromString(“2016-02-29 12:24:26”) print(date) 23 Answers 23

NSDate get year/month/day

How can I get the year/month/day of a NSDate object, given no other information? I realize that I could probably do this with something similar to this: NSCalendar *cal = [[NSCalendar alloc] init]; NSDateComponents *components = [cal components:0 fromDate:date]; int year = [components year]; int month = [components month]; int day = [components day]; But … Read more