⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 这个程序实现的是一个计时的功能
💻 C
字号:
#include <std.h>
#include "Config1cfg.h"
#include "math.h"
//#include "commontypedef.h"
#include "stdlib.h"

#define SECOND_A_DAY 86400
#define DAY_A_YEAR 365

struct st_Datetime
{
	int year;
	int month;
	int day;
	int hour;
	int minute;
	int second;
};

void main(void)
{
	struct st_Datetime st_CurDt = {2001, 1, 1, 0, 0, 0};
	
	static struct st_Datetime st_OriDt = {2000, 1, 1, 0, 0, 0};
	
	int DayAccumulate[12] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
	

	int i, j = 0;
	
	int s32_DayToSec, s32_HourToSec, s32_MinuteToSec, s32_SecondToSec;
	
	long int s32_DaySomeYear, s32_DaySomeMonth, s32_SecondTotal;


//计算到xxxx年1月1日00时00分00秒一共多少天
	for (i = st_OriDt.year; i < st_CurDt.year; i++)
	{
		if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
		{		   
			j++;
		}
	}
	
	s32_DaySomeYear = (st_CurDt.year - st_OriDt.year) * DAY_A_YEAR + j;
    
		
//计算从xxxx年1月1日00时00分00秒到xxxx年x月x日xx时xx分xx秒一共多少天
	if(st_CurDt.month == 1)
	{
		s32_DaySomeMonth = st_CurDt.day - st_OriDt.day;
	}
	else if(st_CurDt.month == 2)
	{
		s32_DaySomeMonth = DayAccumulate(st_CurDt.month - 2) + (st_CurDt.day - st_OriDt.day); 
	}
 	else 
	{
	 	if((st_CurDt.year % 4 == 0 && st_CurDt.year % 100 != 0) || st_CurDt.year % 400 == 0 && st_CurDt.month > 2))
		{
			s32_DaySomeMonth = DayAccumulate[st_CurDt.month - 2] + 1 + (st_CurDt.day - st_OriDt.day); 
		}
	    else
		{
			s32_DaySomeMonth = DayAccumulate[st_CurDt.month - 2] + (st_CurDt.day - st_OriDt.day);
		}
	}
	
//计算累计的时间 s32_SecondTotal

    s32_DayToSec = ((st_CurDt.day - st_OriDt.day) + s32_DaySomeMonth + s32_DaySomeYear) * SECOND_A_DAY;
    s32_HourToSec = (st_CurDt.hour - st_OriDt.hour) * 3600;
	s32_MinuteToSec = (st_CurDt.minute - st_OriDt.minute) *60;
	s32_SecondToSec = st_CurDt.second;
				
	s32_SecondTotal = s32_DayToSec + s32_HourToSec + s32_MinuteToSec + s32_SecondToSec;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -