Some functions and codes about date
来源:互联网 发布:网络语言的好处 编辑:程序博客网 时间:2024/05/16 23:53
#include <stdio.h>
typedef struct _DATES
{
int year;
int month;
int day;
}DATES;
//获取某月的天数
int GetDaysOfMonth(int year, int month)
{
bool judge = false;
int daysOfMonth[12] = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if ((year%4 == 0) && (year%100 != 0) || (year%400 == 0))
{
judge = true;
}
if (month == 2)
{
return judge ? 29:28;
}
else
{
return daysOfMonth[month - 1];
}
}
//获取指定的两个月份之间的天数
int GetDaysBetweenMonth(DATES start, DATES end)
{
int daysStart, daysEnd;
int subMonth;
int sum = 0;
subMonth = end.month - start.month;
daysStart = GetDaysOfMonth(start.year, start.month);
if (subMonth == 0)
{
return (end.day - start.day);
}
if (subMonth < 0)
{
return (daysStart - start.day);
}
else
{
daysEnd = end.day;
sum = daysStart - start.day + daysEnd;
for (int m=1; m<=subMonth-1; m++)
{
sum += GetDaysOfMonth(start.year, start.month + m);
}
return sum;
}
}
void main()
{
DATES dateStart, dateEnd;
int days;
dateStart.year = 2010;
dateEnd.year = 2010;
printf("Please input the month,day:/n");
scanf("%d,%d", &dateStart.month, &dateStart.day);
printf("Input the end date:/n");
scanf("%d,%d",&dateEnd.month, &dateEnd.day);
days = GetDaysBetweenMonth(dateStart, dateEnd);
printf("The days is %d/n", days);
}
- Some functions and codes about date
- Some functions about time
- Some tips about Abstract base classes and pure virtual functions
- some codes about broadcast intent
- some function about Date
- some functions about judge the String type
- Some interesting facts about static member functions in C++
- List sessions and some details about them
- Some Tips and Tricks about Qt
- some questions and tips about java
- some functions
- mysql 12.7 Date and Time Functions
- [Javascript] Some very simple functions for Word and Excel handling
- An article about Equals and GetHashCode functions in C#
- An article about Equals and GetHashCode functions in C#
- some js codes
- Some useful java codes
- Some CV Codes
- 注册MSN了
- linux下主要工具的安装
- 如何使用HttpClient认证机制
- sql server2005 bak文件强制还原数据库
- 对offsetLeft,offsetTop,scrollLeft,scrollTop几个属性的理解
- Some functions and codes about date
- 快速排序JAVA实现
- Harry Potter and the Deathly Hallows
- 开发时struts,xml 最好
- 用apache架设网页服务器还是主流
- Fedora 13 中mysql 数据文件夹换位置后不能启动服务的解决方法
- POJ 1469 courses
- 周报-struts2 中chain、redirect、redirectaction的区别
- interceptor