Get the system time and format

// #include <time.h>

int GetAndFormatSystemTime(char* timeBuff)
{
    if (timeBuff == NULL) {
        return ERR;
    }

    time_t temp;
    struct tm* curTime;

    time(&temp);
    curTime = localtime(&temp);

    sprintf(timeBuff, 
            "[ %d-%d-%d %d:%d:%d ]",
            curTime->tm_year + 1900,
            curTime->tm_mon + 1,
            curTime->tm_mday,
            curTime->tm_hour,
            curTime->tm_min,
            curTime->tm_sec);
    return OK;
}

 

Guess you like

Origin www.cnblogs.com/tongyishu/p/11691079.html