You can get the date 5 months from now in Swift by using the Calendar
and DateComponents
classes. Here's an example code snippet:
main.swift189 chars6 lines
First, we create a Date
object representing the current date. Then, we get the current calendar by calling Calendar.current
. Next, we create a DateComponents
object and set the month
property to 5 to represent five months from now. Finally, we use the date(byAdding:to:)
method of the calendar object to get the date 5 months from now. The fiveMonthsFromNow
variable will contain the resulting Date
object.
gistlibby LogSnag