How to get month & year from NSDate?

后端 未结 2 693
野的像风
野的像风 2021-01-16 09:02

Is there any way/ method to seperate month & year form NSDate?

I just need to display current month & year? Any Example?

相关标签:
2条回答
  • 2021-01-16 09:27
    NSDate *date = [NSDate date];
    NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
    NSInteger year = [dateComponents year];
    NSInteger month = [dateComponents month];
    [calendar release];
    

    cheers endo

    0 讨论(0)
  • 2021-01-16 09:33

    This could be done by using NSDateComponents

    0 讨论(0)
提交回复
热议问题