Comparing NSDates without time component

后端 未结 17 1748
轮回少年
轮回少年 2020-11-27 12:49

In a swift playground, I have been using

NSDate.date() 

But, this always appears with the time element appended. For my app I need to ignor

17条回答
  •  臣服心动
    2020-11-27 13:21

    For iOS7 support

    let dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd"
    let date1String = dateFormatter.stringFromDate(date1)
    let date2String = dateFormatter.stringFromDate(date2)
    if date1String == date2String {
        println("Equal date")
    }
    

提交回复
热议问题