the c programming language 上关于日期和天数转换的一段源码

static char daytab[2][13] = { 
 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 
 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} 
 }; 
 /* day_of_year: set day of year from month & day */ 
 int day_of_year(int year, int month, int day) 
 { 
 int i, leap; 
 leap = year%4 == 0 && year%100 != 0 || year%400 == 0; 
 for (i = 1; i < month; i++) 
 day += daytab[leap][i]; 
 return day; 
 } 
 /* month_day: set month, day from day of year */ 
 void month_day(int year, int yearday, int *pmonth, int *pday) 
 { 
 int i, leap; 
 leap = year%4 == 0 && year%100 != 0 || year%400 == 0; 
 for (i = 1; yearday > daytab[leap][i]; i++) 
 yearday -= daytab[leap][i]; 
 *pmonth = i; 
www.linuxidc.com
Linux公社(LinuxIDC.com) 是包括Ubuntu,Fedora,SUSE技术,最新IT资讯等Linux专业类网站。
 *pday = yearday; 
 } 
 

你可能感兴趣的:(the c programming language 上关于日期和天数转换的一段源码)