0

I'm trying to build app that shows to different dates, a start date and time along with an end date and time, i would like it to display the difference between date and time example (1 day 3 hours) then calculates a cost. As I'm new to swift i wanted to know if NSDate() or UIDatePicker is best option at the moment all i have is

  let startDate = NSDate()
  let endDate = NSDate()
  let calendar = NSCalendar.currentCalendar()
  let dateComponents =     calendar.components(NSCalendarUnit.CalendarUnitHours, fromDate: start, toDate: enddt, options: nil) 
  let Hours= datecomponents.hours
  println("Hours: \(Hours)")

Thanks in advance

SmithyT
  • 1
  • 2

1 Answers1

0

Yes, you should use NSDate to work with dates and UIDatePicker is usually the best option to get a date from user.

Your code is correct. Also if you need more help about difference between two dates you could check this question for example.

Community
  • 1
  • 1
Avt
  • 16,927
  • 4
  • 52
  • 72
  • thanks AVT, just quick one to ask your is best to use a UITableVC or can use a normal VC when trying to use calculations as when the result show from different date i wanted then calculate a price once i get the result – SmithyT Apr 23 '16 at 09:46