c语言strftime demo

time.h 格式化日期

time()获取当前日期的秒,localtime()获取当前时间字段, strftime格式化日期到字符串

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <time.h>


int main() {
    time_t rawtime;
    struct tm *timeInfo = NULL;
    char buff[80];

    time(&rawtime);
    printf("rawtime:%d\n", rawtime);
    timeInfo = localtime(&rawtime);
    strftime(buff, sizeof(buff),"%Y-%m-%d %H:%M:%S",  timeInfo);
    printf("buff:%s\n", buff);

    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/luckygxf/p/12508201.html