zoukankan      html  css  js  c++  java
  • iOS 判断两个日期之间的间隔

    本文转载至 http://www.cnblogs.com/Ewenblog/p/3891791.html

     

    两个时间段,判断之间的相差,做一些时间范围限制使用

        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];

        [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];

        NSDate* toDate     = [dateFormatter dateFromString:@"20140702142033"];

        NSDate*  startDate    = [ [ NSDate alloc] init ];

        NSCalendar* chineseClendar = [ [ NSCalendar alloc ] initWithCalendarIdentifier:NSGregorianCalendar ];

        NSUInteger unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit;

        

        NSDateComponents *cps = [ chineseClendar components:unitFlags fromDate:startDate  toDate:toDate  options:0];

        

        NSInteger diffYear = [cps year];

        NSInteger diffMon = [cps month];

        NSInteger diffDay = [cps day];

        NSInteger diffHour = [cps hour];

        NSInteger diffMin = [cps minute];

        NSInteger diffSec = [cps second];

        NSLog(@" From Now to %@, diff: Years: %d  Months: %d, Days; %d, Hours: %d, Mins:%d, sec:%d", [toDate description], diffYear, diffMon, diffDay, diffHour, diffMin,diffSec );

  • 相关阅读:
    B1028人口普查
    B1004成绩排名
    B1041考试座位号
    A1009 Product of Polynomials多项式相乘
    A1002 A+B for Polynomials 多项式相加
    B1010一元多项式求导
    A1065 A+Band C(64 bit)
    A1046 Shortest Distance 最短路径
    排序
    windows 平台使用wireshark命令行抓包
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/5707404.html
Copyright © 2011-2022 走看看