其他分享
首页 > 其他分享> > c语言获取系统时间

c语言获取系统时间

作者:互联网

void getCurrentDateTime(char* current_datetime)
{
    time_t nowtime;
    struct tm* timeinfo;
    time(&nowtime);
    timeinfo = localtime(&nowtime);
    int xtn = timeinfo->tm_year + 1900;
    xtn = xtn % 2000;
    int xty = timeinfo->tm_mon + 1;
    int xtr = timeinfo->tm_mday;
    int xts = timeinfo->tm_hour;
    int xtf = timeinfo->tm_min;
    int xtm = timeinfo->tm_sec;
    snprintf(current_datetime, 18, "%d-%d-%d %d:%d:%d", xtn, xty, xtr, xts, xtf, xtm);
}

char* current_datetime = malloc(18);
memset(current_datetime, 0, 18);
getCurrentDateTime(current_datetime);

 

标签:语言,timeinfo,int,系统,datetime,current,获取,tm,xtn
来源: https://www.cnblogs.com/zhjh256/p/16257204.html