日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

8266获取网络时间

發(fā)布時間:2025/3/8 编程问答 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 8266获取网络时间 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

8266獲取網(wǎng)絡(luò)時間


今天第一次用阿里的博客寫點(diǎn)東西感受一下....sntp.sync("ntp1.aliyun.com",function()print("sync succeeded")end,function(index)print("failed : "..index)end)

用的SNTP

然后打印時間

time = rtctime.epoch2cal(rtctime.get() timer = string.format("%04d;%02d;%02d;%02d;%02d;%02d;%01d", time["year"], time["mon"], time["day"], time["hour"]+8, time["min"], time["sec"],time["wday"]) --print(timer) local DataList = split(timer, ';'); year = tonumber(DataList[1]); month = tonumber(DataList[2]); day = tonumber(DataList[3]); hour = tonumber(DataList[4]); minute = tonumber(DataList[5]); second = tonumber(DataList[6]); weekday = tonumber(DataList[7]); print(year,month,day,hour,minute,second,weekday)

現(xiàn)在說一下問題
國際時間和北京時間相差8小時,所以會發(fā)現(xiàn)所獲得的時間會在北京時間8點(diǎn)的時候變化

年 月 日 時 分 秒 星期2018 3 3 31 0 0 7 2018 3 3 31 0 1 7 2018 3 3 31 0 2 7 2018 3 3 31 0 3 7 2018 3 3 31 0 4 7 2018 3 3 31 0 5 7 2018 3 3 31 0 6 7 2018 3 3 31 59 54 7 2018 3 3 31 59 55 7 2018 3 3 31 59 56 7 2018 3 3 31 59 57 7 2018 3 3 31 59 58 7 2018 3 3 31 59 59 7 2018 3 4 8 0 0 1 2018 3 4 8 0 1 1 2018 3 4 8 0 2 1 2018 3 4 8 0 3 1 2018 3 4 8 59 51 1 2018 3 4 8 59 52 1 2018 3 4 8 59 53 1

會問怎么會有31小時,這就是問題點(diǎn)1

國際時間小時是從0-23變化,加了8小時所以變化為8-31
所以獲得時間后直接加8小時是不對的
而且還會發(fā)現(xiàn)日子總是在每天的8點(diǎn)變化,肯定不對

最簡單的方法

time = rtctime.epoch2cal(rtctime.get()+28800) timer = string.format("%04d;%02d;%02d;%02d;%02d;%02d;%01d", time["year"], time["mon"], time["day"], time["hour"], time["min"], time["sec"],time["wday"]) --print(timer) local DataList = split(timer, ';'); year = tonumber(DataList[1]); month = tonumber(DataList[2]); day = tonumber(DataList[3]); hour = tonumber(DataList[4]); minute = tonumber(DataList[5]); second = tonumber(DataList[6]); weekday = tonumber(DataList[7]); print(year,month,day,hour,minute,second,weekday)

time = rtctime.epoch2cal(rtctime.get()+28800)
直接設(shè)置系統(tǒng)的時間加8小時,這樣的話系統(tǒng)就能讓日期在零點(diǎn)的時候變化,而且不會向上面似得出現(xiàn)31這種不對的時間

現(xiàn)在的數(shù)據(jù)

2018 3 5 23 59 50 2 2018 3 5 23 59 51 2 2018 3 5 23 59 52 2 2018 3 5 23 59 53 2 2018 3 5 23 59 54 2 2018 3 5 23 59 55 2 2018 3 5 23 59 56 2 2018 3 5 23 59 57 2 2018 3 5 23 59 58 2 2018 3 5 23 59 59 2 2018 3 6 0 0 0 3 2018 3 6 0 0 1 3 2018 3 6 0 0 2 3 2018 3 6 0 0 3 3 2018 3 6 0 0 4 3 2018 3 6 0 0 5 3 2018 3 6 0 0 6 3 2018 3 6 0 0 7 3 2018 3 6 0 0 8 3 2018 3 6 0 0 9 3 2018 3 6 0 0 10 3

總結(jié)

以上是生活随笔為你收集整理的8266获取网络时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。