先把curl放到/system/bin下,开机执行以下函数
time_synced=0
time_sync()
{
if [ $time_synced -eq 0 ];then
rawtime=`curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "http://time.tianqi.com/beijing" |grep "电脑时间" | tr -cd "[0-9]"`
reslen=`echo $rawtime|wc -c`
if [ $reslen -eq 15 ];then
MM=`echo $rawtime | cut -b 5,6`
dd=`echo $rawtime | cut -b 7,8`
HH=`echo $rawtime | cut -b 9,10`
mm=`echo $rawtime | cut -b 11,12`
yyyy=`echo $rawtime | cut -b 1,2,3,4`
ss=`echo $rawtime | cut -b 13,14`
fixtime=$MM$dd$HH$mm$yyyy.$ss
date $fixtime set
time_synced=1
echo "successfully sync time="$fixtime >> /data/timesync.txt
fi
fi
}
即从http://time.tianqi.com/beijing网页解析出北京时间,转为纯数字,判断是否为14位有效时间,解析出年月日时分秒,重新排列,按照date的格式要求设置到系统。