avatar
w*c
1
another question:
in shell script, how to compare date? for instance, give the
"19/Mar/2002:17:14:06", ask if this time is within a specified
time slot, for example, last 50 minutes? how could you implment
it?
thanks! Here are a lot of unix guru.really benefit from it.
avatar
s*i
2
you can use something like this to compare two time:
#!/bin/bash
E_NOTSAMEDAY=-197
E_PARAM_ERR=-198
if [ -z "$2" ]
then
exit $E_PARAM_ERR
fi
day1=`echo $1|cut -d: -f1`
hour1=`echo $1|cut -d: -f2`
min1=`echo $1|cut -d: -f3`
#sec1=`echo $1| cut -d: -f4`
day2=`echo $2|cut -d: -f1`
hour2=`echo $2|cut -d: -f2`
min2=`echo $2|cut -d: -f3`
#sec2=`echo $2| cut -d: -f4`
if [[ "$day1" != "$day2" ]]
then
exit $E_NOTSAMEDAY
fi
diffh=$((hour2-hour1))
diffm=$((min2-min1))
difft=$((diffh*60+diffm))
ech

【在 w****c 的大作中提到】
: another question:
: in shell script, how to compare date? for instance, give the
: "19/Mar/2002:17:14:06", ask if this time is within a specified
: time slot, for example, last 50 minutes? how could you implment
: it?
: thanks! Here are a lot of unix guru.really benefit from it.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。