Search code examples
objective-cnsstringnscalendar

Objective C - NSCalendar to a NSString


I need to convert a NSCalendar to a NSString to show date and time splitted in two differents UITextView I can't found a way to do this. All examples convert NSDate to NSString, but I need to do that with a NSCalendar!

Thanks for your help and sorry for my poor english


Solution

  • Unlike Java where java.util.Calendar objects represent instances of time, NSCalendar is a class that lets you perform operations on NSDate objects, without representing a particular point in time at all.

    You can use an instance of NSCalendar to split an NSDate into date components (day, month, hour, etc.) according to a specific calendar, to add a number of time units to an NSDate, or compose a bunch of date-time components into an NSDate. You could then convert the NSDate to a string using NSDateFormatter.