webserver/headers/htime.hpp

28 lines
476 B
C++
Raw Normal View History

2025-04-28 20:47:53 +08:00
#pragma once
#include <ctime>
#include <cstring>
#include <string>
class Htime
{
time_t tv;
public:
Htime() {}
std::string get_local_time_now()
{
static char buffer[128];
struct tm *_local_time = nullptr;
memset(buffer, 0x0, sizeof(buffer));
tv = time(nullptr);
_local_time = localtime(&tv);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", _local_time);
return std::string(buffer);
}
};