C语言笔记——时间运算

http://www.cnblogs.com/VRS_technology/archive/2010/09/21/1832564.html

prehourTime ()

{

  time_t curtime;

  time_t resulttime;

  struct tm *st;

  time (&curtime);

  st = localtime (&curtime);

  st->tm_hour -= 1;

  resulttime = mktime (st);

  st = localtime (&resulttime);

  return st;

}

 struct tm *prehourTime ();

 struct tm *prehour = prehourTime ();

 char fn[100];

 char fn2[100];

 char fp[100];                 //file path

 char year[5];

 char month[2];

 char day[2];

 char hour[2];

  sprintf (year, "%d", prehour->tm_year + 1900);

  sprintf (month, "%02d", prehour->tm_mon + 1);

  sprintf (day, "%02d", prehour->tm_mday);

  sprintf (hour, "%02d", prehour->tm_hour);

你可能感兴趣的:(C语言)