-
-
Save sturdysturge/8628a9fcd26e5d6821b14a59a573b767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
@available(iOS 16.0, *) | |
struct ContentView: View { | |
@StateObject var viewModel = ViewModel() | |
var body: some View { | |
NavigationStack { | |
Form { | |
Section("Seconds since 1970") { | |
TextField("Timestamp", value: $viewModel.timestamp, | |
formatter: viewModel.timestampFormatter) | |
.keyboardType(.numberPad) | |
.onChange(of: viewModel.timestamp) { timestamp in | |
viewModel.date = Date(timeIntervalSince1970: timestamp) | |
} | |
} | |
Section("UTC Date") { | |
DatePicker("Select", selection: $viewModel.date) | |
.environment(\.timeZone, .gmt) | |
.onChange(of: viewModel.date) { date in | |
viewModel.timestamp = date.timeIntervalSince1970 | |
} | |
} | |
Section("Local time zone") { | |
Text(TimeZone.current.identifier) | |
Text(viewModel.timeZoneOffsetString) | |
} | |
Section("Local Date") { | |
DatePicker("Select", selection: $viewModel.date) | |
} | |
} | |
.navigationTitle("Timestamp Converter") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment