0
let calendar = Calendar.current
var component = DateComponents()
        
component.minute = 15
component.hour = 3
component.day = 12
component.month = 7
component.year = 2021
        
guard let startDate = calendar.date(from: component) else {return}

when I am debugging I see

(lldb) po sessions[0].startDate
▿ 2021-07-12 10:15:00 +0000
  - timeIntervalSinceReferenceDate : 647777700.0

pretty much everything is spot on except for the hour

vksdbvksbvk
  • 104
  • 1
  • 7
  • Are you in GMT with 3hours difference? If that's the case, that's normal. The date is `2021-07-12 10:15:00 +0000` with `+0000` meaning at time UTC, which might be your time. – Larme Feb 25 '21 at 19:00
  • To get the time using your locale try `po sessions[0].startDate.description(with: .current) ` – Joakim Danielson Feb 25 '21 at 19:02
  • Not related to your question but you can simplify your code using the DateComponents date property `guard let startDate = DateComponents(calendar: .current, year: 2021, month: 7, day: 12, hour: 3, minute: 15).date else {` – Leo Dabus Feb 25 '21 at 19:06
  • 2
    @JoakimDanielson I didn't know about `Date.description(with:)`. thanks for that. You can also use `DateFormatter.localizedString(from:dateStyle:timeStyle:)` – Duncan C Feb 25 '21 at 19:30

0 Answers0