-2
var timeIntervalSince1970: NSTimeInterval {get}

I just hope someone can help me with this.

Ben
  • 1
  • 1

1 Answers1

1

TimeInterval Since 1970 returns epoch time in seconds, you can change it to return milliseconds multiplying it by 1000.

Date().timeIntervalSince1970 * 1000

if you need it to count from start of today you can use calendar method startOfDay(for: Date)


extension Date {
    var startOfDay: Date {
        Calendar.current.startOfDay(for: self)
    }
    var millisecondsSince1970: Int {
        .init(timeIntervalSince1970 * 1000)
    }
}

let millisecondsSince1970 = Date().millisecondsSince1970             // 1604931753291
let startOfDayMsSince1970 = Date().startOfDay.millisecondsSince1970  // 1604890800000
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571