String description of NSDate

前端 未结 4 1984
星月不相逢
星月不相逢 2021-01-31 10:30

I have the following code:

[ [NSDate date] descriptionWithLocale: @\"yyyy-MM-dd\" ]

I want it to return a date in the following format: \"2009-

4条回答
  •  悲&欢浪女
    2021-01-31 11:25

    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
    [dateFormatter release];  // delete this line if your project uses ARC
    NSLog(@"%@",dateString); 
    

提交回复
热议问题