Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created May 1, 2023 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/74d1e6c26ffa97ebffe169e654dc8de6 to your computer and use it in GitHub Desktop.
Save sturdysturge/74d1e6c26ffa97ebffe169e654dc8de6 to your computer and use it in GitHub Desktop.
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