# Contains? & lttime.h & gt
# Contains? & ltcstdio & gt
# Contains? & ltiostream & gt
Use? Namespace? std
/* Time to convert the shaping time into a string format */
int? TimeNumToStr(time_t? Time,? Charles? *pBuf)
{
struct? tm? * tmT
tmT? =? Local time (& time);
What if? (NULL? ==? tmT)
{
//printf("tmT? Is it? Empty. Time? =? %u, \n ",time);
Return? - 1;
}
/* Time format: month-day-year? Hours: minutes: seconds */
sprintf(pBuf,? " %02d-%02d-%02d? %02d:%02d:%02d”,
tmT->; tm_mon? +=? 1,
tmT->; tm_mday,
tmT->; tm_year? -? 100,/* The time in TM is the number of years from 1900 to now, and only two digits are displayed here, so 100*/
tmT->; Tm _ hour,
tmT->; tm_min,
tmT->; Tm _ second
);
Return? 0;
}
int? main(int? argc,? Charles? *argv[])
{
/* Get the current time */
time_t? tmNow? =? Time (empty);
Charles? cTmp[50]? =? {0};
/* The conversion time is in the specified format */
TimeNumToStr(tmNow,cTmp); .
/* Output results */
cout & lt& ltcTmp<。 & ltendl
Return? 0;
} copy the TimeNumToStr function into your code, and pay attention to the related header files. Test results: