【Foundation-18-2】NSDate.h - 时间操作


FOUNDATION_EXPORTNSString *const NSSystemClockDidChangeNotificationNS_AVAILABLE(10_6,4_0);



@interface NSDate (NSExtendedDate)


// 时间间隔

@property (readonly)NSTimeInterval timeIntervalSinceNow;

@property (readonly)NSTimeInterval timeIntervalSince1970;

+ (NSTimeInterval)timeIntervalSinceReferenceDate;

- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate;

    [date1 timeIntervalSinceNow];
    [date1 timeIntervalSince1970];
    [date1 timeIntervalSinceReferenceDate];
    [date1 timeIntervalSinceDate:date1];





// 拼接时间间隔

- (instancetype)dateByAddingTimeInterval:(NSTimeInterval)tiNS_AVAILABLE(10_6,2_0);

    NSDate *date = [date1 dateByAddingTimeInterval:60];



//判断 返回符合条件的 date

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

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

//    NSDate  *date = [date1 earlierDate:date2];
    NSDate *date = [date2 laterDate:date1];
   



//比较时间先后顺序

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

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

   

 NSComparisonResult comper = [date1 compare:date2];
    if (comper == NSOrderedAscending) {
        NSLog(@"升");
    }else if (comper == NSOrderedSame){
        NSLog(@"same");
    }else if (comper == NSOrderedDescending){
        NSLog(@"降");
    }else{
        NSLog(@"error");
    }
    
    
    if ([date1 isEqualToDate:date2]) {
        NSLog(@"eq");
    }else{
        NSLog(@"noeq");
    }




// 0 时区 的时间 现在   (本地化时间 研究 NSLocale

@property (readonly, copy) NSString *description;

- (NSString *)descriptionWithLocale:(id)locale;

  NSLog(@"description:%@",date1.description);
  NSLog(@"description:%@",[date1 descriptionWithLocale:@8]);

    




@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值