日付の月の最初の日、年の最初の日を取得する必要があります
(ほとんどの場合、入力日は現在の日付です[NSDate date]
)
入手方法を教えてください、
EG今日の現在の日付=3-MAY-2015
次のように出力が必要です。
First_Date_month =1-MAY-2015
First_Date_year =1-JAN-2015
お時間をいただきありがとうございます
日付の月の最初の日、年の最初の日を取得する必要があります
(ほとんどの場合、入力日は現在の日付です[NSDate date]
)
入手方法を教えてください、
EG今日の現在の日付=3-MAY-2015
次のように出力が必要です。
First_Date_month =1-MAY-2015
First_Date_year =1-JAN-2015
お時間をいただきありがとうございます
NSDateComponents を使用して日月と年を見つけることができ、必要に応じて NSDate を作成できます
NSDateComponents *components = [calendar components:units fromDate:[NSDate date]];
[components setDay:1];
self.currentDate = [calendar dateFromComponents:components];
int m = components.month;
int y = components.year;
int d = components.day;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy MM dd"];
NSDate *firstDateOfMonth = [df dateFromString:[NSString stringWithFormat:@"%@ %@ 01",y,m]];
NSDate *firstDateOfYear = [df dateFromString:[NSString stringWithFormat:@"%@ 01 01",y]];