Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 865
Michał Ziobro Avatar asked Dec 07 '22 10:12

Michał Ziobro


1 Answers

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)!)
like image 144
Asperi Avatar answered May 16 '23 09:05

Asperi