talking about timestamp and date Time interchange C language
* * * * * * ctime.h * * * Created on:may 2016 */#ifndef ctime_h_ #define CTIME_H_ #include "common/micro_type.h" #define Offset_second 946684800/* 1970/1/1/0/0/0 2000/1/1/0/0/0֮*///#define OFFSET_SECOND 0/* 20 00/1/1/0/0/0 2000/1/1/0/0/0֮*/#define Second_of_day 86400/* 1 * typedef STRUC
T date_time {uint16 iyear;
UInt16 Imon;
UInt16 Iday;
UInt16 Ihour;
UInt16 imin;
UInt16 ISec;
UInt16 imsec;
} date_time;
void Getdatetimefromsecond (unsigned long lsec, date_time *ttime);
#endif/* Ctime_h_ * * * ctime.c * * Created on:may 2016 * author:root * #include "common/micro_type.h"
#include "ctime.h" uint8 dayofmon[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; /* 1970/1/1/0/0/0ʱ*/unsigned long getsecondtime (date_time *date_time) {uint16 iyear, Imon, Iday, Ihour, IM
In, ISec;
Iyear = date_time->iyear;
Imon = date_time->imon; Iday = Date_time->idaY
Ihour = date_time->ihour;
Imin = date_time->imin;
ISec = date_time->isec;
UInt16 I, cyear=0;
unsigned long countday=0; For (i=1970 i<iyear; i++)/*ͳ1970굽֮ǰ*/{if ((i%4==0) && (i%100!=0)) | | (i%400==0))
cyear++;
} countday = Cyear * 366 + (iyear-1970-cyear) * 365; For (I=1 i<imon; i++) {if (i==2) && (((iyear%4==0) && (iyear%100!=0)) | |
(iyear%400==0)))
Countday + 29;
else Countday + = dayofmon[i-1];
} Countday + = (iDay-1);
Countday = Countday*second_of_day + (unsigned long) ihour*3600 + (unsigned long) imin*60 + ISec;
return countday; /*ʱ1970/1/1/0/0 */void Getdatetimefromsecond (unsigned long lsec, date_time *ttime) {uint16 i,j,i
Day;
unsigned long lday; 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))
* * */ Lday-= 366;
else lday-= 365;
i++; if (lday = 365) &&! ( ((i%4==0) && (i%100!=0) | | (i%400==0)))
/*ƽ*/{lday = 365;
i++; } ttime->iyear = i; /*õ*/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;
} Ttime->imon = j+1;
Ttime->iday = lday+1;
Ttime->ihour = ((lsec/3600) +8)%24;//Here Note that the world time has been added to Beijing times 8, ttime->imin = (lsec% 3600)/60;
ttime->isec = (lsec% 3600)% 60; }
The above this article on the time stamp and date time to each other to the C language is small to share the whole of the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.