Objective-C Language NSDate Converting NSDate to NSString

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

If ww have NSDate object, and we want to convert it into NSString. There are different types of Date strings. How we can do that?, It is very simple. Just 3 steps.

  1. Create NSDateFormatter Object
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  1. Set the date format in which you want your string.
    dateFormatter.dateFormat = @"yyyy-MM-dd 'at' HH:mm";
  1. Now, get the formatted string

     NSDate *date = [NSDate date]; // your NSDate object
     NSString *dateString = [dateFormatter stringFromDate:date];
    

This will give output something like this: 2001-01-02 at 13:00

Note:

Creating an NSDateFormatter instance is an expensive operation, so it is recommended to create it once and reuse when possible.



Got any Objective-C Language Question?