Can u please tell me how to extract a date from UIDatePicker, i have extracted the month but i am not able to extract the date,Please help me out
Thank You
Can u please tell me how to extract a date from UIDatePicker, i have extracted the month but i am not able to extract the date,Please help me out
Thank You
You can access the
date
property of theUIDatePicker
class to get the date!The
NSDate
object can be extracted by just accessing thedate
property of the object:If you want to extract detailed information about what month, day and year a person has chosen, this is a little bit more complex (but just a little bit). The solution is to use an NSCalendar reference - it is likely that you'd want to use Gregorian.
Now you should use an unsigned integer unit flags to specify which units you want to extract from a date (i.e. day, day-of-the-month, year, era etc.). Use a bitwise | to select multiple unit flags:
Now create a date components object:
From this components date, you can now extract integer values of what you have mentioned in the unitFlags integer:
All other properties (i.e. day, day-of-the-month, era etc.) are undefined in such a components object - remember, you can only extract what you've explicitly said you want to extract.
Finally, free the calendar object to avoid memory leaks:
Hope this helps. For more information, see Apple reference: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/DatesAndTimes/DatesAndTimes.html