Passing a formatted NSDate

后端 未结 3 633
后悔当初
后悔当初 2021-01-28 19:26

Formatted dates that I am passing to an instance method are not saving/printing the correct date. Can someone please help?

Calling method code snippets:

         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 19:57

    Next works perfect for me:

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    
    NSDate *date = [dateFormatter dateFromString:@"13-09-2011"];
    NSLog(@"%@", date);
    

提交回复
热议问题