您可以使用
date命令来实现。
mandate将为您提供更多详细信息。bash脚本可能在以下几行上显示(似乎可以在Ubuntu 10.04 bash4.1.5上正常工作):
#!/bin/bash# Date 1dt1="2011-11-11 11:11:11"# Compute the seconds since epoch for date 1t1=`date --date="$dt1" +%s`# Date 2 : Current datedt2=`date +%Y-%m-%d %H:%M:%S`# Compute the seconds since epoch for date 2t2=`date --date="$dt2" +%s`# Compute the difference in dates in secondslet "tDiff=$t2-$t1"# Compute the approximate hour differencelet "hDiff=$tDiff/3600"echo "Approx hour diff b/w $dt1 & $dt2 = $hDiff"
希望这可以帮助!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)