【NO.2】set day of year from month & day
2014-05-30 13:56
381 查看
#include "stdafx.h" int day_of_year(int year, int month, int day); int _tmain(int argc, _TCHAR* argv[]) { int year = 0, month = 0, day = 0; printf("please input year month day(yyyy month day)\n"); scanf_s("%4d %2d %2d", &year, &month, &day); int DayOfYear = day_of_year(year, month, day); printf("%4d-%2d-%2d is the %d days in this year", year, month, day, DayOfYear); getchar(); } /*day_of_year: set day of year from month & day*/ 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} }; int day_of_year(int year, int month, int day) { int i, leap; if ((year % 4) == 0 && (year % 100 != 0) || (year % 400 == 0)) { leap = 1; } else { leap = 0; } for(i=1; i < month; i++) { day+= daytab[leap][i]; } set day of year from month & day return day; }
相关文章推荐
- SQL 标量函数-----&gt;日期函数 day() 、month()、year()、DATEADD()、ATEDIFF()、DATENAME()、DATEPART() GETDATE()
- MonthOfTheYear、WeekOfTheYear、WeekOfTheMonth、DayOfTheYear ... 相对时间
- mysql 详解YEAR() MONTH() DAYOFMONTH()日期函数
- mysql时间函数之dayofweek,dayofmonth,dayofyear,weekofyear用法
- mysql 详解YEAR() MONTH() DAYOFMONTH()日期函数
- Calendar:它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等 日历字段
- '?' can only be specfied for Day-of-Month -OR- Day-of-Week.
- SQL 标量函数----->日期函数 day() 、month()、year()、DATEADD()、ATEDIFF()、DATENAME()、DATEPART() GETDATE()
- boost准模板库date迭代器(指针)使用以及常用的两个静态成员函数is_leap_year()和end_of_month_day()
- settimeofday and gettimeofday
- warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
- PowerTip of the Day from powershell.com上周汇总
- PowerTip of the Day from powershell.com上周汇总(三)
- 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
- Select n numbers from 1 to m with all of array 'all' and none of array 'none'
- PowerTip of the Day from powershell.com上周汇总(三)
- PowerTip of the Day from powershell.com上周汇总(二)
- PowerTip of the Day from powershell.com上周汇总
- SQL SERVER 2005恢复数据错误解决:The backup set holds a backup of a database other than the existing 'XXX' database
- How to eliminate the compile error "conversion from 'double ' to 'float ', possible loss of data"