C++时间计算

#include <chrono>
#include <ctime>

/*
 * Pause funciton to pause tha animation for a few milliseconds
 * so that it doesn't go by too fast.
 */
void pause(double ms) {
    auto start= std::chrono::high_resolution_clock::now();
    while(true) {
       auto end = std::chrono::high_resolution_clock::now();
       auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
       if(duration > ms) return;
    }
}
#include <ctime>
    time_t startTime = time(NULL);
    while(difftime(time(NULL),startTime) <= excuteTimeInS){
        UpdateGraph(*p_G);
    }

推荐阅读更多精彩内容