31 lines
621 B
C++
31 lines
621 B
C++
#include "common.h"
|
|
|
|
#include <time.h>
|
|
#include <chrono>
|
|
#include <ctime>
|
|
|
|
/**
|
|
* @brief GetCurrentTime 获取当前时间
|
|
* @return
|
|
*/
|
|
std::string getCurrentTimeString() {
|
|
|
|
std::time_t t = std::time(NULL);
|
|
char mbstr[100];
|
|
std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d %H:%M:%S",
|
|
std::localtime(&t));
|
|
std::string strTime = mbstr;
|
|
return strTime;
|
|
}
|
|
|
|
std::string getCurrentShortTimeString() {
|
|
|
|
std::time_t t = std::time(NULL);
|
|
char mbstr[100];
|
|
std::strftime(mbstr, sizeof(mbstr), "%H:%M:%S",
|
|
std::localtime(&t));
|
|
std::string strTime = mbstr;
|
|
return strTime;
|
|
}
|
|
|