zoukankan      html  css  js  c++  java
  • vtime.hpp

    //vov
    #ifndef VTIME_HPP
    #define VTIME_HPP
    
    #include <cstdio>
    #include <ctime>
    #include <string>
    #include <chrono>
    #include <sys/time.h>
    
    static const std::string vTimeStamp() {
      time_t tt=time(NULL);
      struct tm *stm=localtime(&tt);
      char tmp[50];
      sprintf(tmp, "%04d%02d%02d%02d%02d%02d",
        1900 + stm->tm_year,
        1 + stm->tm_mon,
        stm->tm_mday,
        stm->tm_hour,
        stm->tm_min,
        stm->tm_sec);
      std::string res(tmp);
      return res;
    }
    
    static const std::string vTimeStampMilli() {
      struct timeval tv;
      struct tm * time_ptr;
      gettimeofday(&tv, NULL);
      time_ptr = std::localtime(&tv.tv_sec);
      char accT[128];
      std::sprintf(accT, "%d-%02d-%02d %02d:%02d:%02d.%.04ld",
      time_ptr->tm_year + 1900,
      time_ptr->tm_mon + 1,
      time_ptr->tm_mday,
      time_ptr->tm_hour,
      time_ptr->tm_min,
      time_ptr->tm_sec,
      tv.tv_usec);
      std::string ret(accT);
      return ret;
    }
    
    static const std::chrono::steady_clock::time_point vTimePoint() {
        return std::chrono::steady_clock::now();
    }
    
    static double vTimePointDiff(std::chrono::steady_clock::time_point t1,
        std::chrono::steady_clock::time_point t2) {
        return std::chrono::duration_cast<std::chrono::duration<double>>(t2-t1).count()*1000;
    }
    
    #endif
    
  • 相关阅读:
    二分法查找数据
    循环队列的操作
    堆栈的操作
    链表的各种操作
    尾插法创建链表
    头插法创建链表
    链表简介
    <map>的常用操作
    linux下php添加自带扩展
    快速排序
  • 原文地址:https://www.cnblogs.com/smallredness/p/10758540.html
Copyright © 2011-2022 走看看