iphone Get current year as string

后端 未结 5 1186
迷失自我
迷失自我 2021-02-01 01:33

How do I get current year as string in Obj-C ?

Also how do I compare the same using another year value ?

Is it advisable to do a string comparision OR dirctly ye

5条回答
  •  执念已碎
    2021-02-01 02:29

    you can get by following code in objective c

    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
    int year = [components year];
    NSString *strFromyear = [NSString stringWithFormat:@"%d",year];
    

提交回复
热议问题