Do that method utilizing a DateFormatter
, comparable to:
struct ContentView: View {
@State non-public var startTime: Date = .now
var formatter: DateFormatter {
let frmt = DateFormatter()
frmt.dateFormat = "MMMM dd, yyyy 'at' hh:mm"
frmt.locale = Locale(identifier: "da")
frmt.timeZone = TimeZone(abbreviation: "UTC") // zulu (UTC) time
return frmt
}
var physique: some View {
VStack {
DatePicker("_", choice: $startTime, displayedComponents: .hourAndMinute)
.labelsHidden()
.datePickerStyle(.wheel)
Textual content(formatter.string(from: startTime)) // zulu (UTC) time
}
.atmosphere(.locale, .init(identifier: "da"))
}
}
Or this:
struct ContentView: View {
@State non-public var startTime: Date = .now
@State non-public var zuluTime = ""
var formatter: DateFormatter {
let frmt = DateFormatter()
frmt.dateFormat = "hh:mm"
frmt.locale = Locale(identifier: "da")
frmt.timeZone = TimeZone(abbreviation: "UTC") // zulu (UTC) time
return frmt
}
var physique: some View {
VStack {
DatePicker("_", choice: $startTime, displayedComponents: .hourAndMinute)
.labelsHidden()
.datePickerStyle(.wheel)
Textual content(zuluTime) // zulu (UTC) time
Textual content(startTime, fashion: .time) // native time
}
.atmosphere(.locale, .init(identifier: "da"))
.onChange(of: startTime) {
zuluTime = formatter.string(from: startTime)
}
.onAppear {
zuluTime = formatter.string(from: startTime)
}
}
}