时间格式化函数strftime



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

int main()
{
  char timebuf[100]={0};
  time_t timep; 
  struct tm *p_tm; 
  
  timep = time(NULL); 
  p_tm = localtime(&timep); /*获取本地时区时间*/
  
  strftime(timebuf, sizeof(timebuf),"%Y-%m-%d %H:%M:%S",p_tm);
  
  printf("%s\n", timebuf);

  return 0;
}

结果:2015-06-12 03:44:54



posted @ 2017-06-04 19:52  claireyuancy  阅读(244)  评论(0编辑  收藏  举报