1.读取日期

Linux:~ # date
Mon Dec 17 03:16:53 EST 2018

2.格式日期并打印

Linux:~ # date "+%d %B %Y"
17 December 2018

3.设置日期时间

Linux:~ # date -s "16 Dec 2018 5:20:21"
Sun Dec 16 05:20:21 EST 2018

上述命令为设置系统日期为:2018年12月16日 5点20分21秒

4.查看命令运行时间

#!/bin/bash
start=$(date +%s)
echo "hellwo world"
sleep 1s
echo "after 1s"
end=$(date +%s)
difference=$((end - start))
echo Time Taken to execute commands is $difference seconds.

执行结果

【Shell】获取设置日期和延时

5.生成延时50秒的脚本


  1 #!bin/bash
  2 echo Count:
  3 tput sc #存储光标位置
  4 
  5 #循环50s
  6 for count in `seq 0 50` #循环生成数字
  7 do
  8   tput rc #恢复之前存储的光标位置
  9   tput ed  #清除从当前光标位置到行尾之间的所有内容
 10   echo -n $count
 11   sleep 1
 12   done
View Code

相关文章:

  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2021-09-14
  • 2022-12-23
  • 2021-10-20
  • 2022-02-20
相关资源
相似解决方案