在Android shell里校准时间

先把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的格式要求设置到系统。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值