2

I'm creating a method that is reliant on a certain amount of time having elapsed. It has to be readable by a non-technical person, so the time has to be in days

let daysBetweenRequests = 130

But for that to work with an TimeInterval comparison, it needs to be in milliseconds. In Objective-C or Swift, is there an equivalent to Java's TimeUnit class that will perform the conversion of days to milliseconds for me, or do I need to roll the conversion myself? Something like:

let daysAsMilliseconds = TimeConverter.convert(from: daysBetweenRequests, to: .milliseconds) 

I'm fine doing it, but it seems like there would be a built-in, and I can't seem to find one. Thanks!

h.and.h
  • 690
  • 1
  • 8
  • 26
  • 3
    `NSDateComponentsFormatter`? There is also this `NSCalendar` method: https://developer.apple.com/documentation/foundation/nscalendar/1409577-datebyaddingcomponents?language=objc ? – Larme Apr 22 '19 at 19:48
  • Cool, thanks! If you provide an example as an answer, I'd be happy to upvote and select it as the answer. Thanks again! – h.and.h Apr 22 '19 at 19:58
  • 1
    https://stackoverflow.com/questions/5067785/how-do-i-add-1-day-to-an-nsdate ? – Larme Apr 22 '19 at 20:53
  • Possible duplicate of [How do I add 1 day to an NSDate?](https://stackoverflow.com/questions/5067785/how-do-i-add-1-day-to-an-nsdate) – The1993 Jul 24 '19 at 05:59

0 Answers0