C++ mktime returning random dates

前端 未结 3 906
走了就别回头了
走了就别回头了 2020-12-21 05:55

I\'m trying to convert a date string to a time_t, but mktime() is returning seemingly random dates:

string datetime = \"2014-12-10 10:30\";
stru         


        
3条回答
  •  青春惊慌失措
    2020-12-21 06:48

    The below code would do the work, if you want current system time in an format

     time_t current_time;
     struct tm *loctime;
    
     memset(buffer,0,strlen(buffer));
     current_time = time(NULL);
     loctime = localtime(¤t_time);
     strftime(buffer,250,"--> %d/%m/%y  %H:%M:%S",loctime);
    

提交回复
热议问题