-
-
Save sturdysturge/74d1e6c26ffa97ebffe169e654dc8de6 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 | |
class ViewModel: ObservableObject { | |
@Published var timestamp: TimeInterval | |
@Published var date: Date | |
var timestampFormatter: NumberFormatter = { | |
var formatter = NumberFormatter() | |
formatter.allowsFloats = false | |
return formatter | |
}() | |
var timeZoneOffsetString: String { | |
let hourDifference: Int = TimeZone.current | |
.secondsFromGMT(for: date) / 3600 | |
if hourDifference == 0 { | |
return "UTC" | |
} else if hourDifference > 0 { | |
return "UTC +\(hourDifference)" | |
} else { | |
return "UTC \(hourDifference)" | |
} | |
} | |
init() { | |
let date = Date() | |
self.timestamp = date.timeIntervalSince1970 | |
self.date = date | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment