datepickerswiftuiuidatepicker

SwiftUI: DatePicker is it possible to display date/time in other timezone then current?


In UIDatePicker we can do something like this

datePicker.timeZone = TimeZone(secondsFromGMT: 5*60*60) 

in order to specify timezone of datepicker.

But how about doing this in DatePicker in SwiftUI, I cannot find any such param or modifier.


Solution

  • It is possible to do with SwiftUI .environment modifier as in below example

    DatePicker("Due Date", selection: $selected,
        displayedComponents: [.date, .hourAndMinute]
    )
    .environment(\.timeZone, TimeZone(secondsFromGMT: 5*60*60)!)