How can I initialize a date to NSdate?

前端 未结 3 1270
你的背包
你的背包 2021-01-11 20:10

I want to give, for example, 12/11/2005 in the format of mm/dd/yyyy. Can I initialize 12/11/2005 to NSDate directly? Any

3条回答
  •  借酒劲吻你
    2021-01-11 20:38

    What you need to do is something like this:

    NSDateFormatter *mmddccyy = [[NSDateFormatter alloc] init];
    mmddccyy.timeStyle = NSDateFormatterNoStyle;
    mmddccyy.dateFormat = @"MM/dd/yyyy";
    NSDate *d = [mmddccyy dateFromString:@"12/11/2005"];
    NSLog(@"%@", d);
    

提交回复
热议问题