C++ 用c+解析localtime+;

C++ 用c+解析localtime+;,c++,ctime,C++,Ctime,是否有一种简单的“初学者”方法可以使用将当前时间转换为具有 int month int day int year 对于它的成员变量?谢谢。time\u t tt=time(空);//获取当前时间作为时间 time_t tt = time(NULL); // get current time as time_t struct tm* t = localtime(&tt) // convert t_time to a struct tm cout << "Month " &l

是否有一种简单的“初学者”方法可以使用
将当前时间转换为具有

int month
int day
int year
对于它的成员变量?谢谢。

time\u t tt=time(空);//获取当前时间作为时间
time_t tt = time(NULL); // get current time as time_t
struct tm* t = localtime(&tt) // convert t_time to a struct tm
cout << "Month "  << t->tm_mon 
     << ", Day "  << t->tm_mday
     << ", Year " << t->tm_year
     << endl
struct tm*t=localtime(&tt)//将t_时间转换为struct tm
cout如果有localtime\r,那么您应该使用localtime\r而不是localtime,因为这是localtime的可重入版本

#include <ctime>
#include <iostream>

int main()
{
    time_t tt = time(NULL); // get current time as time_t
    tm  tm_buf;
    tm* t = localtime_r(&tt, &tm_buf); // convert t_time to a struct tm

    std::cout << "Month "  << t->tm_mon
              << ", Day "  << t->tm_mday
              << ", Year " << t->tm_year
              << std::endl;
    return 0;
}
#包括
#包括
int main()
{
time_t tt=time(NULL);//获取当前时间作为time
tm_buf;
tm*t=localtime\u-r(&tt,&tm\u-buf);//将t\u-time转换为struct-tm
std::cout所说的“标准日期对象”是指
时间\u t
?请在此处阅读有关localtime的内容: