Unix固定时间的当前时间减法

时间:2015-11-13 11:24:27

标签: shell unix

要求是在凌晨4点之后运行脚本,随机时间调用脚本,因此在脚本的开头添加了下面的代码片段:

while [ $(date +"%H%M%S") -lt 040000 ]
do
    curTime=$(date -u +"%H%M%S")
    reqTime=040000
    subTime=$(expr $reqTime - $curTime)
    if [ $cntTime -ge 0 ]
    then    
        sleep $cntTime
    fi
done

检查curTime < 4AM是否为#include "clang/Tooling/CommonOptionsParser.h" // For reading compiler switches from the command line #include "clang/Tooling/Tooling.h" static cl::OptionCategory MyToolCategory("SearchGlobalSymbols"); static cl::extrahelp MoreHelp("\nMore help text..."); // Text that will be appended to the help text. You can leave out this line. /* Your code (definition of your custom RecursiveASTVisitor and ASTConsumer) */ /* Define class MyASTFrontendAction here, derived from ASTFrontendAction */ int main(int argc, const char **argv) { /* Your code */ CommonOptionsParser op(argc, argv, MyToolCategory); // Parse the command-line arguments ClangTool Tool(op.getCompilations(), op.getSourcePathList()); // Create a new Clang Tool instance (a LibTooling environment) return Tool.run(newFrontendActionFactory<MyASTFrontendAction>().get()); // Run custom Frontendaction } ,如果是,则从凌晨4点减去curTime,并在提醒时间内休息(以秒为单位)。但减法不会在几秒钟内发生,它是数字。

1 个答案:

答案 0 :(得分:0)

如果你使用bash和GNU / Linux,

echo $((`date +%s` - `date -d 'today 04:00' +%s`))

为您提供当天04:00以来的秒数。