登录 注册
当前位置:主页 > 资源下载 > 11 > sntp时间转换.txt下载

sntp时间转换.txt下载

  • 更新:2024-08-23 18:33:20
  • 大小:16KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:C - 后端
  • 格式:TXT

资源介绍

安信可wifi模块esp8266获取互联网时间,精确到小时分钟/秒/年月日等。 static void ICACHE_FLASH_ATTR SetDsTime() { uint32_t time = sntp_get_current_timestamp(); if(time>0) { os_timer_disarm(&SetdsTimer;); os_printf("time:%d\r\n",time); os_printf("date:%s\r\n",sntp_get_real_time(time));//传入time参数给sntp_get_real_time char* tttt="Wed Dec 07 16:34:45 2016"; os_strcpy(tttt,sntp_get_real_time(time)); //因为后期使用的os_strncpy函数不能自动将字符串中的\0字符串结束符号一并拷贝进来,所以这里根据年月日的长度构造函数,并初始化后各位有\0符号,不至于函数崩溃 char chsec[3]={""}; char chmin[3]={""}; char chhour[3]={""}; char chwday[4]={""}; char chmday[3]={""}; char chmon[4]={""}; char chyear[5]={""}; //待截取字符串指针名即为字符串的起始地址,移动多少个后即为第I位的起始地址,也就是截取的起点 os_strncpy(chsec,tttt+17,2); os_strncpy(chmin,tttt+14,2); os_strncpy(chhour,tttt+11,2); os_strncpy(chwday,tttt,3); os_strncpy(chmday,tttt+8,2); os_strncpy(chmon,tttt+4,3); os_strncpy(chyear,tttt+20,4); os_printf("\r\nSubdate:%s,%s,%s,%s,%s,%s-----%s\r\n",chyear,chmon,chmday,chhour,chmin,chsec,chwday);//传入time参数给sntp_get_real_time //赋值给时间设置变量 timedate.tm_year=(chyear[2]-48)*10+(chyear[3]-48); if(strcmp(chmon,"Jan")==0) timedate.tm_mon=1; else if(strcmp(chmon,"Feb")==0) timedate.tm_mon=2; else if(strcmp(chmon,"Mar")==0) timedate.tm_mon=3; else if(strcmp(chmon,"Apr")==0) timedate.tm_mon=4; else if(strcmp(chmon,"May")==0) timedate.tm_mon=5; else if(strcmp(chmon,"Jun")==0) timedate.tm_mon=6; else if(strcmp(chmon,"Jul")==0) timedate.tm_mon=7; else if(strcmp(chmon,"Aug")==0) timedate.tm_mon=8; else if(strcmp(chmon,"Sep")==0) timedate.tm_mon=9; else if(strcmp(chmon,"Oct")==0) timedate.tm_mon=10; else if(strcmp(chmon,"Nov")==0) timedate.tm_mon=11; else if(strcmp(chmon,"Dec")==0) timedate.tm_mon=12; timedate.tm_mday=(chmday[0]-48)*10+(chmday[1]-48); timedate.tm_hour=(chhour[0]-48)*10+(chhour[1]-48); timedate.tm_min=(chmin[0]-48)*10+(chmin[1]-48); timedate.tm_sec=(chsec[0]-48)*10+(chsec[1]-48); if(strcmp(chwday,"Mon")==0) timedate.tm_wday=1; else if(strcmp(chwday,"Tue")==0) timedate.tm_wday=2; else if(strcmp(chwday,"Wed")==0) timedate.tm_wday=3; else if(strcmp(chwday,"Thu")==0) timedate.tm_wday=4; else if(strcmp(chwday,"Fri")==0) timedate.tm_wday=5; else if(strcmp(chwday,"Sat")==0) timedate.tm_wday=6; else if(strcmp(chwday,"Sun")==0) timedate.tm_wday=7; os_printf("\r\nSet Time:%d,%d,%d,%d,%d,%d-----%d\r\n",timedate.tm_year,timedate.tm_mon,timedate.tm_mday,timedate.tm_hour,timedate.tm_min,timedate.tm_sec,timedate.tm_wday); ds3231_setTime(timedate); }