当前位置:网站首页>51 SCM time stamp correlation function
51 SCM time stamp correlation function
2022-06-25 09:34:00 【silno】
The function uses long Variable , Comparative proportion RAM, If the space of single-chip microcomputer is tight, don't use it , Will be able to mcu It's silly .
/******* timestamp Time stamp function Start **********/
#define SECOND_OF_DAY 86400 // How many seconds a day
idata uchar DayOfMon[]={31,28,31,30,31,30,31,31,30,31,30,31};/********************************************************************************************************
* FunctionName : GetSecondTime()
* Description : Date format is converted to unix time
* EntryParameter :
* ReturnValue :
********************************************************************************************************/
unsigned long GetSecondTime(void)
{
idata uint rYear,i,Cyear=0;
idata uchar rMon,rDay,rHour,rMin,rSec;
idata unsigned long CountDay = 0;
rSec =BCD_to_DEC(RTC[6]);
rMin =BCD_to_DEC(RTC[5]);
rHour =BCD_to_DEC(RTC[4]);
rDay =BCD_to_DEC(RTC[2]);
rMon =BCD_to_DEC(RTC[1]);
rYear= 2000+BCD_to_DEC(RTC[0]);
for(i = 1970; i < rYear; i++)
{
if(((i%4==0) && (i%100!=0)) || (i%400==0)) Cyear++;
}
CountDay = Cyear * 366 + (rYear-1970-Cyear) * 365;
for(i=1; i<rMon; i++)
{
if((i==2) && (((rYear%4==0)&&(rYear%100!=0)) || (rYear%400==0)))
CountDay += 29;
else
CountDay += DayOfMon[i-1];
}
CountDay += (rDay-1);
CountDay = CountDay*SECOND_OF_DAY + (unsigned long)rHour*3600 + (unsigned long)rMin*60 + rSec;
CountDay = CountDay - 8*3600;// Beijing time is transformed into world time
return CountDay;
}
/********************************************************************************************************
* FunctionName : GetDateTimeFromSecond()
* Description : unix time Convert to common format
* EntryParameter :
* ReturnValue :
********************************************************************************************************/
void GetDateTimeFromSecond(unsigned long lSec)
{
uint i,j,iDay;
idata unsigned long lDay;
lSec = lSec + 8*3600;// Convert to Beijing time
lDay = lSec / SECOND_OF_DAY;
lSec = lSec % SECOND_OF_DAY;
i = 1970;
while(lDay > 365)
{
if(((i%4==0) && (i%100!=0)) || (i%400==0))// Leap year
{
lDay -= 366;
}else
{
lDay -= 365;
}
i++;
}
if((lDay == 365) && !(((i%4==0)&&(i%100!=0)) || (i%400==0)))
{
lDay -= 365;
i++;
}
RTC[0] = i-2000;// year
for(j=0;j<12;j++)
{
if((j==1) && (((i%4==0)&&(i%100!=0)) || (i%400==0)))
{
iDay = 29;
}else
{
iDay = DayOfMon[j];
}
if(lDay >= iDay)
{
lDay -= iDay;
}
else
{
break;
}
}
RTC[1] = j+1; // month
RTC[2] = lDay+1;// Japan
RTC[4] = ((lSec / 3600))%24; // when
RTC[5] = (lSec % 3600) / 60; // branch
RTC[6] = (lSec % 3600) % 60; // second
}
/******** Time stamp function end ***********/
边栏推荐
- Voiceprint Technology (I): the past and present life of voiceprint Technology
- Is it safe to open an account with Great Wall Securities by mobile phone?
- Is it safe to open an account in a mobile phone or a securities company?
- Nodejs using the express framework demo
- Remove the mosaic, there's a way, attached with the running tutorial
- [design completion - opening report] zufeinfo 2018 software engineering major (including FAQ)
- 2021mathorcupc topic optimal design of heat dissipation for submarine data center
- Data-driven anomaly detection and early warning of 21 May Day C
- matplotlib matplotlib中plt.grid()
- Specific usage of sklearn polynomialfeatures
猜你喜欢

Benefits and types of cloud network technology

neo4jDesktop(neo4j桌面版)配置自动启动(开机自启)

How can games copied from other people's libraries be displayed in their own libraries

C语言刷题随记 —— 猴子吃桃

How much money have I made by sticking to fixed investment for 3 years?
![[IOU] intersection over union](/img/17/a3e2144dfbd9248034cae285ee85bd.jpg)
[IOU] intersection over union

Compile time annotations for custom annotations (retentionpolicy.class)

Remove the mosaic, there's a way, attached with the running tutorial

Oracle one line function Encyclopedia

Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
随机推荐
Voiceprint Technology (I): the past and present life of voiceprint Technology
Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
Work of the 15th week
Online notes on Mathematics for postgraduate entrance examination (8): Kego equations, eigenvalues and eigenvectors, similarity matrix, quadratic series courses
3、 Automatically terminate training
在指南针上面开户好不好,安不安全?
compiling stm32f4xx_ it. c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
Oracle one line function Encyclopedia
《乔布斯传》英文原著重点词汇笔记(一)【 Introduction 】
Prepare for the 1000 Android interview questions and answers that golden nine silver ten must ask in 2022, and completely solve the interview problems
TLAB mechanism of JVM object memory allocation and TLAB process in G1
Matplotlib plt grid()
Notes on key words in the original English work biography of jobs (III) [chapter one]
Register the jar package as a service to realize automatic startup after startup
Is it safe for Huatai Securities to open a stock account on it?
Is it safe to buy stocks and open accounts through the account QR code of the account manager? Want to open an account for stock trading
With the QQ group file storage function of super nice, you immediately have n cloud disks that are easy to download and never expire
行业春寒回暖,持续承压的酒店企业于何处破局?
socket编程——epoll模型
35 websites ICER must know