Nic
Nic

Reputation: 617

How to get month & year from NSDate?

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

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

Upvotes: 1

Views: 11126

Answers (2)

endo.anaconda
endo.anaconda

Reputation: 2468

NSDate *date = [NSDate date];
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
[calendar release];

cheers endo

Upvotes: 6

Espo
Espo

Reputation: 41929

This could be done by using NSDateComponents

Upvotes: 1

Related Questions