1、时间转字符串函数

size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr );

2、字符串转时间函数

char *strptime(const char *s, const char *format, struct tm *tm);

#include <stdio.h>
#include <time.h>


int main()
{
        struct tm tm_time;
        strptime("2010-11-15 10:39:30", "%Y-%m-%d %H:%M:%S", &tm_time);
        printf("%ld/n", mktime(&tm_time));
        printf("-------------------------------------/n");


        char szBuf[256] = {0};
        time_t timer = time(NULL);
        strftime(szBuf, sizeof(szBuf), "%Y-%m-%d %H:%M:%S", localtime(&timer));
        printf("%s/n", szBuf);

        return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-12-26
  • 2021-04-12
  • 2021-06-10
  • 2022-12-23
猜你喜欢
  • 2022-03-02
  • 1970-01-01
  • 2022-02-08
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案