ios当年的天数 [英] number of day of current year in ios

查看:60
本文介绍了ios当年的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道今天的天数是在今年。例如,如果今天是2012年3月15日,我应该得到75(31 + 29 + 15)。或者我们可以简单地说今天和今年1月1日之间的天数。
有人可以帮助我吗?

I want to find number of day today is in current year. e.g, if today is Mar15, 2012 I should get 75(31 + 29 + 15). Or we can simply say that number of days between today and Jan01 of current year. can someone please help me?

问候

Pankaj

Regards
Pankaj

推荐答案

使用NSCalendar的ordinalityOfUnit方法获取年份中的日期编号 - 在unUnit中指定NSDayCalendarUnit:NSYearCalendarUnit

Use the ordinalityOfUnit method of the NSCalendar to get the day number in the year - specify the NSDayCalendarUnit inUnit:NSYearCalendarUnit

NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDate *today = [NSDate date];
NSInteger dc = [currentCalendar  ordinalityOfUnit:NSDayCalendarUnit
                                                  inUnit:NSYearCalendarUnit
                                                 forDate:today];

2012年9月25日给出269

gives 269 for Sept 25th 2012

这篇关于ios当年的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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