HOW TO PRINT NSDATE USING NSLOG?

marcel ethan

Total Post:105

Points:735
Posted by  marcel ethan
 560  View(s)
Ratings:
Rate this:

I want to print NSDate in NSLog, but its not printing date correctly.

NSDateFormatter *format = [NSDateFormatter new];
[format setDateFormat: @"YYYY-MM-DD"];
NSDate *date = [NSDate date];
NSLog(@"Date: %@",format);

Can anyone tell me, what's wrong in my code..!

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: How to print NSDate using NSLog?

    To print date in NSLog use stringFromDate method of NSDateFormatter class.
    Here, we provide the example, change your code by this code:

    NSDateFormatter *format = [NSDateFormatter new];
    [format setDateFormat: @"YYYY-MM-DD"];
    NSLog(@"Date: %@",[format stringFromDate:Your_Date_obj]);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!