由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - how to compare date
相关主题
How to find "ush.h"? Is it in the system?[转载] makefile question. urgent!!!!!!!!!!!!!!!!!!!!!!!!
[转载] pop3 programming problem关于tar的愚昧问题
关于group的属性[转载] a simple but weird question about the usage of "test" in RH6.2 !
Re: 为什么emacs自动给我加^M.为什么有时用windows的telnet,每打一个字母会出现两个相同的字母呀?
有关Unix shell script的问题如何显示出“*”
vi 一问.HELP!! (CXTERM)
一个关于命令行的小问题how to setup lib path?
[转载] How to compare the CPU time of two algorithms?Shell Question
相关话题的讨论汇总
话题: compare话题: echo话题: cut话题: date话题: time
进入Unix版参与讨论
1 (共1页)
w****c
发帖数: 10
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.
s**i
发帖数: 30
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.

1 (共1页)
进入Unix版参与讨论
相关主题
Shell Question有关Unix shell script的问题
how to find a specified file in the unix?vi 一问.
how to grep with more than one patterns in tcsh?一个关于命令行的小问题
how to use batch file to ftp files in UNIX?[转载] How to compare the CPU time of two algorithms?
How to find "ush.h"? Is it in the system?[转载] makefile question. urgent!!!!!!!!!!!!!!!!!!!!!!!!
[转载] pop3 programming problem关于tar的愚昧问题
关于group的属性[转载] a simple but weird question about the usage of "test" in RH6.2 !
Re: 为什么emacs自动给我加^M.为什么有时用windows的telnet,每打一个字母会出现两个相同的字母呀?
相关话题的讨论汇总
话题: compare话题: echo话题: cut话题: date话题: time