Skip to content

How to Calculate Tomorrow’s Noon Time

  • by

Use the following code snippet to get the time for tomorrow at noon (12pm). This standard approach is taken from Apple’s WWDC session “Efficiency Awaits: Background Tasks in SwiftUI,” and it can be adapted to retrieve any specific time based on today’s date.

let today = Calendar.current.startOfDay (for: .now)
if let tomorrow = Calendar.current.date(byAdding: •day, value: 1, to: today) {
    let noonComponent = DateComponents (hour: 12)
    let noon = Calendar. current.date(byAdding: noonComponent, to: tomorrow)
}

Tags:

Leave a Reply