-2

I'm trying to convert an NSDate to a "HH:mm" time string. In the past, I could use an NSDateFormatter's stringFromDate method, but now, it seems that method will only accept a Date (NOT NSDate) object. How can I do this? I will accept an answer that allows me to cast an NSDate as a Date, or that allows me to directly convert an NSDate to a formatted time string.

My casting attempts ("_time" contains an NSDate, and _date contains a Date. These don't compile):

let dateformatter = DateFormatter()
dateformatter.dateFormat = "HH:MM"
return dateformatter.string(from: (Date)_time)

And:

let myNSDate = NSDate(_date)
dylanthelion
  • 1,760
  • 15
  • 23

1 Answers1

4

I will accept an answer that allows me to cast an NSDate as a Date

Say as Date.

matt
  • 515,959
  • 87
  • 875
  • 1,141