获取当前日期、时间
#include <chrono>
#include <ctime>
void ThkModDataBaseMng::GetCurTime(CString& strDate, CString& strTime)
{
auto now = std::chrono::system_clock::now();
// 将当前时间转换为时间戳
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
// 使用 std::localtime 将时间戳转换为本地时间
std::tm* local_time = std::localtime(&now_c);
strDate.Format("%d-%02d-%02d", 1900 + local_time->tm_year, local_time->tm_mon + 1, local_time->tm_mday);
strTime.Format("%02d:%02d:%02d", local_time->tm_hour, local_time->tm_min, local_time->tm_sec);
}
获取本机IP地址
char szHostName[256];
if (gethostname(szHostName, sizeof(szHostName)) == 0)
{
hostent* host = gethostbyname(szHostName);
if (host)
{
for (int i = 0; host->h_addr_list[i] != 0; i++)
{
struct in_addr addr;
memcpy(&addr, host->h_addr_list[i], sizeof(struct in_addr));
CString strIP = inet_ntoa(addr);
return strIP;
}
}
}