如何在Swift 3.0中比较日期? [英] how to compare date in swift 3.0?

查看:78
本文介绍了如何在Swift 3.0中比较日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个约会,我想比较一下。
如何比较日期?
我必须约会对象。请说 modificateionDate 较旧的 updatedDate

I have two dates and I want to compare it. How can I compare dates? I have to date objects. Say modificateionDate older updatedDate.

那么比较日期的最佳实践是什么?

So which is the best practice to compare dates?

推荐答案

日期 现在符合 可比较 协议。因此,您只需使用< > == 比较两个 Date 类型的对象。

Date now conforms to Comparable protocol. So you can simply use <, > and == to compare two Date type objects.

if modificateionDate < updatedDate {
     //modificateionDate is less than updatedDate
}

这篇关于如何在Swift 3.0中比较日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆