How to get 1 hour ago from a date in iOS swift?

前端 未结 13 748
一向
一向 2020-12-04 13:35

I have been researching, but I couldnt find exact solution for my problem. I have been trying to get 1 hour ago from a date. How can I achieve this in swift?

相关标签:
13条回答
  • 2020-12-04 14:06

    Swift3:

    let now = Date()
    let tempCalendar = Calendar.current
    let alteredDate = tempCalendar.date(byAdding: .hour, value: -1, to: now)
    
    0 讨论(0)
提交回复
热议问题