美文网首页IOS
NSDate的一些简单用法整理

NSDate的一些简单用法整理

作者: SHChen | 来源:发表于2015-06-21 18:27 被阅读164次

    A、创建或者初始化的方法

          1、返回现在的时间

           NSDate*now = [NSDate date];

          2、在一定的时间基准上来确定另一个时间

          -  (instancetype) dateByAddingTimeInterval:(NSTimeInterval) ti

          3、在某一个时间的基础上加多少秒之后返回一个新的时间

           - (id)addTimeInterval:(NSTimeInterval)seconds

    B、时间之间相互比较的方法

           1、返回两个时间中相对较早的那个时间

            - (NSDate*)earlierDate:(NSDate*)anotherDate;

            2、返回两个时间当中相对较晚的时间

            - (NSDate*)laterDate:(NSDate*)anotherDate;

            3、判断两个时间是否相等

           - (BOOL)isEqualToDate:(NSDate*)otherDate;

           4、将两个时间进行比较

           - (NSComparisonResult)compare:(NSDate*)other;

              得出的结果主要有:

                    NSOrderedAscending——后面的时间要大于调用这个方法的时间

                    NSOrderedSame——相等

                    NSOrderedDescending——后面的时间小于调用这个方法的时间

    相关文章

      网友评论

        本文标题:NSDate的一些简单用法整理

        本文链接:https://www.haomeiwen.com/subject/nfwsqttx.html