c++ rfc3339转时间戳

记录一下

char * timestamp_to_rfc3339_string(time_t timestamp) {
    char timestamp_str[22];
    struct tm *ret;
#ifndef _WIN32
    struct tm gmt;
    ret = gmtime_r(&timestamp,&gmt);
#else
    ret = gmtime(&timestamp);
#endif
    snprintf(timestamp_str, sizeof(timestamp_str), "%4d-%02d-%02dT%02d:%02d:%02dZ",
    ret->tm_year + 1900, ret->tm_mon + 1, ret->tm_mday, ret->tm_hour, ret->tm_min, ret->tm_sec);
    return em_strdup(timestamp_str);
}

猜你喜欢

转载自blog.csdn.net/quanhaoH/article/details/128866769