'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 1:[1]
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)!)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |