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;
}

  

 

posted on 2020-03-17 00:39  luckygxf  阅读(260)  评论(0编辑  收藏  举报

导航