Created
March 14, 2018 01:10
-
-
Save KirillKudaev/e9b5ba27cb484d2d0b4e40dd6976d45c to your computer and use it in GitHub Desktop.
epoch swift
This file contains hidden or 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
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