قالب وردپرس درنا توس
Home / IOS Development / How do you get the time difference between a current time and a particular future time? : iOSProgramming

How do you get the time difference between a current time and a particular future time? : iOSProgramming



Use NSCalendar and NSDateComponents to work with human readable date and time components such as year, month, day, hour, minute, etc.

For example:

  la calendar = Calendar.current
leave now = date ()

// Get current year, month and day
were components: DateComponents = calendar.dateComponents ([.era, .year, .month, .day] from: now)

// Set the clock to 8 PM
components.hour = 20
la todayAtEightPm: Date = calendar.date (from: components)!

// Add a day
la imorgenAtEightPm: Date = calendar.date (vedAdding: .day, value: 1, to: todayAtEightPm)!

Source link