[C++][ubuntu]将本地时间格式化为年月日时分秒

Posted FL1623863129

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[C++][ubuntu]将本地时间格式化为年月日时分秒相关的知识,希望对你有一定的参考价值。

话不多说,直接上代码

#include <time.h>
#include<iostream>
  int main()
 
 time_t t = time(0);
 char tmp[32] = NULL ;
 strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", localtime(&t));
  std::string date(tmp);
 std::cout<<date<<std::endl;
return 0;
 

以上是关于[C++][ubuntu]将本地时间格式化为年月日时分秒的主要内容,如果未能解决你的问题,请参考以下文章