時間格式化函數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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章