还是直接上代码了

string get_bcd_str()
{
    string strret;
    char chtimestamp[32]={0};

    struct timeval tv;
    struct tm *tm;

    gettimeofday(&tv, NULL);
    tm = localtime(&tv.tv_sec);

    sprintf(chtimestamp, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
            tm->tm_year + 1900,
            tm->tm_mon + 1,
            tm->tm_mday,
            tm->tm_hour,
            tm->tm_min,
            tm->tm_sec,
            (int) (tv.tv_usec / 1000)
        );

    strret = chtimestamp;
    return strret;
}
本文链接地址:https://const.net.cn/418.html

标签: none

添加新评论