1. C 표준 라이브러리 함수
2. Cocoa 클래스
참조: NSDateComponents Class Reference
참조: Determination of the day of the week # Sakamoto's method
int getDayOfWeek(int year, int month, int day)
{
struct tm *pResultTime;
struct tm targetTime = { 0, 0, 0, day, month-1, year - 1900 };
time_t targetSec = mktime(&targetTime);
pResultTime = localtime(&targetSec);
return pResultTime->tm_wday;
}
2. Cocoa 클래스
참조: NSDateComponents Class Reference
- (int)getDayOfWeek:(int)year month:(int)month day:(int)day
{
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setYear:year];
[dateComponents setMonth:month];
[dateComponents setDay:day];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:dateComponents];
NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:date];
return [weekdayComponents weekday] - 1;
}
int getDayOfWeek2(int year, int month, int day)
{
if(month <= 2) {
year--;
month += 12;
}
int year1 = year/100;
int year2 = year%100;
int weekDay = (day + 26*(month+1)/10 + year2 + year2/4 + year1/4 - year1*2) % 7 - 1;
if (weekDay < 0) {
weekDay += 7;
}
return weekDay;
} 참조: Determination of the day of the week # Sakamoto's method
int dow(int y, int m, int d)
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
'기타 > 자잘한 Tip' 카테고리의 다른 글
BeautifulSoup을 이용한 xml -> sqlite3 데이터로 변환 (2) | 2009.12.18 |
---|---|
sqlite3에서 csv import/export (0) | 2009.08.26 |
Python에서 sqlite3 사용하기 (1) | 2009.08.26 |
텍스트파일 문자셋 변환 스크립트 (6) | 2008.08.25 |
Xcode에서의 Ruby on Rails (8) | 2008.08.20 |