code
#!/bin/bash
start=$(date +%s)
sleep 5;
end=$(date +%s)
take=$(( end - start ))
echo Time taken to execute commands is ${take} seconds.
运行结果:
Time taken to execute commands is 5 seconds.
date命令常用的日期输出格式
内容 | 格式 | 示例 |
---|---|---|
Unix时间(以秒为单位) | %s | 1559468803 |
小时(12小时) | %I | 05 |
小时(24小时) | %H | 17 |
分钟 | %M | 44 |
秒 | %S | 04 |
纳秒 | %N | 747856472 |
年 | %Y | 2019 |
日 | %d | 02 |
星期 | %A | Sunday |
mm/dd/yy | %D | 06/02/19 |