uint8_t BC20_buffer[100];
void get_time()
{
uint16_t x,y;
HAL_UART_Transmit(&huart1,AT_CCLK,sizeof(AT_CCLK),0x40);
HAL_UART_Receive(&huart1,BC20_buffer,sizeof(BC20_buffer),0X50);
for(x=0;x<100;x++)
{
if(BC20_buffer[x]==':')
{
for(y=0;y<24;y++)
{times[y]=BC20_buffer[1 + ++x];}
}
}
double timestamp,year,mon,day,hour,min,sec,Y,M,D,T,X;
double time_to_timestamp()
{
year=(times[0]-48)*1000+(times[1]-48)*100+(times[2]-48)*10+(times[3]-48);
mon=(times[5]-48)*10+(times[6]-48);
day=(times[8]-48)*10+(times[9]-48);
hour=(times[11]-48)*10+(times[12]-48);
min=(times[14]-48)*10+(times[15]-48);
sec=(times[17]-48)*10+times[18]-48;
if (0 >= (int) (mon -= 2))
{
mon += 12;
year -= 1;
}
T=((((unsigned long)(year/4 - year/100 + year/400 + 367*mon/12 + day) +
year*365 - 719499
)*24 + hour
)*60 + min
)*60 + sec;
return T;
}
转换方式借鉴网上代码