How can I get the current number of days in the current month using NSDate or something similar in Cocoa touch?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
NSDateandNSCalendarclasses:todayis anNSDateobject representing the current date; this can be used to work out the number of days in the current month. AnNSCalendarobject is then instantiated, which can be used, in conjunction with theNSDatefor the current date, to return the number of days in the current month using therangeOfUnit:inUnit:forDate:function.days.lengthwill contain the number of days in the current month.Here are the links to the docs for
NSDateandNSCalendarif you want more information.