Truncate NSDate (Zero-out time)

前端 未结 6 891
孤街浪徒
孤街浪徒 2020-12-02 19:02

I want to generate a new NSDate with 0 hours, 0 minutes, and 0 seconds for time. The source date can be any r

6条回答
  •  死守一世寂寞
    2020-12-02 19:07

    I know its late, but there are now better methods: why dont you just use

    Swift 2

    NSCalendar.currentCalendar().dateBySettingHour(0, minute: 0, second: 0, ofDate: yourDateToZeroOutTime, options: [])
    

    Swift 3 would be something without the NS prefix ;)

提交回复
热议问题