Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Round Date to Second
extension Date {
var roundedToSecond: Date {
let date = self
let diff = 1000000000 - Calendar.current.component(.nanosecond, from: date)
return .nanosecond, value: diff, to: date)!
/// USAGE:
let roundedDate = Date().roundedToSecond /// zero nanoseconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.