-5
let startDate=NSDate().dateByAddingTimeInterval(-60*60*24)
let endDate=NSDate().dateByAddingTimeInterval(60*60*24*3)

lblStart.text = i.startDate

I want the startdate show in a label. How can I convert it to a string.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Gregga17
  • 148
  • 7
  • http://stackoverflow.com/questions/28332946/nsdateformatter-stringfromdatensdate-returns-empty-string – Bhavin Bhadani Apr 15 '16 at 12:15
  • http://www.appcoda.com/nsdate/ – Bhavin Bhadani Apr 15 '16 at 12:15
  • Possible duplicate of [Convert String to NSDate with Swift 2](http://stackoverflow.com/questions/33058091/convert-string-to-nsdate-with-swift-2) – MGY Apr 15 '16 at 12:19
  • That isn't the right way to add/subtract days either. You should use NSDateComponents. See http://stackoverflow.com/questions/7197994/how-i-can-get-the-nsdate-of-yesterday. Simply adding/subtracting seconds won't work across daylight savings time changes – Paulw11 Apr 15 '16 at 12:19

1 Answers1

0

You can try lblStart.text = "\(i.startDate)"

To convert a variable to a string or get its value to output onto a label you would do this: "\(variable name)"

AJS
  • 113
  • 9