在NSDate没有其他信息的情况下,如何获得对象的年/月/日?我意识到我可以用类似的东西做到这一点:
NSCalendar *cal = [[NSCalendar alloc] init];
NSDateComponents *components = [cal components:0 fromDate:date];
int year = [components year];
int month = [components month];
int day = [components day];
Run Code Online (Sandbox Code Playgroud)
但这对于像NSDate年/月/日这样简单的事情来说似乎有很多麻烦.还有其他解决方案吗?