Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KirillKudaev/e9b5ba27cb484d2d0b4e40dd6976d45c to your computer and use it in GitHub Desktop.
Save KirillKudaev/e9b5ba27cb484d2d0b4e40dd6976d45c to your computer and use it in GitHub Desktop.
epoch swift
static func getEpochBeginningOfToday(isTomorrow: Bool) -> Int? {
var date = Date()
if isTomorrow {
guard let tomorrowDate = Calendar.current.date(byAdding: .day, value: 1, to: date) else {
return nil
}
date = tomorrowDate
}
let calendar = Calendar.current
var dateComponents = DateComponents()
dateComponents.day = calendar.component(.day, from: date)
dateComponents.month = calendar.component(.month, from: date)
dateComponents.year = calendar.component(.year, from: date)
dateComponents.timeZone = TimeZone(abbreviation: "CST")
let dateTime = Calendar.current.date(from: dateComponents)
guard let timeInterval = dateTime?.timeIntervalSince1970 else { return nil }
return Int((timeInterval * 1000.0).rounded())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment