【问题标题】:Finding difference between the dates from recent date to same date on next year查找从最近日期到明年同一日期的日期之间的差异
【发布时间】:2012-02-15 20:37:26
【问题描述】:

我正在做一个生日剩余应用程序。在那我需要显示生日剩下的天数。 如果用户在日期选择器中选择特定的生日日期,我需要自动更新从他选择的日期起他的生日还剩多少天。任何人都可以通过编码来帮助解决这个问题。 谢谢!

【问题讨论】:

    标签: iphone objective-c ios nsdate


    【解决方案1】:

    我们可以使用 nsdate 来获取当前日期,然后我们必须计算今天日期和选定日期之间有多少天

    【讨论】:

      【解决方案2】:

      下面的代码用于查找到日期和时间之间的间隔,下面的代码对此有帮助

       NSDateComponents *comp=[[NSCalendar currentCalendar] components:(NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:[NSDate date] toDate:"Your date is here" options:0] ;
      
       cell.detailTextLabel.text=[NSString stringWithFormat:@"%d : %d : %d : %d : %d : %d",comp.year,comp.month,comp.day,comp.hour,comp.minute,comp.second];
      

      它可能对您的应用有所帮助

      愉快的编码

      @samuel

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-07
        • 2022-01-10
        • 2022-10-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多