欢迎各位兄弟 发布技术文章
这里的技术是共享的
#!/bin/bash
#
sudo systemsetup -setusingnetworktime off #关闭网络时间同步
echo "请输入您的时间,时间格式为 2023-01-01 01:01 " #echo "Please enter your time"
read time
echo "时间 是 $time" # echo "time is $time"
month=`echo "${time}" | cut -f2 -d-`
if [ `echo ${month} | wc -c` = 2 ];then month="0${month}" ; fi
day=`echo "${time}" | cut -f3 -d- | cut -f1 -d' '`
if [ `echo ${day} | wc -c` = 2 ];then day="0${day}" ; fi
hour=`echo "${time}" | cut -f3 -d- | cut -f2 -d' ' | cut -f1 -d:`
if [ `echo ${hour} | wc -c` = 2 ];then hour="0${hour}" ; fi
minute=`echo "${time}" | cut -f3 -d- | cut -f2 -d' ' | cut -f2 -d:`
if [ `echo ${minute} | wc -c` = 2 ];then minute="0${minute}" ; fi
year=`echo "${time}" | cut -f1 -d-`
#echo "${month}${day}${hour}${minute}${year}"
sudo date "${month}${day}${hour}${minute}${year}"
echo "时间修改成功,是 `date` "