C++ 打印当前时间

//打印当前时间
string
warn_export::timetoStr(){ char tmp[64]; time_t t = time(NULL); tm *_tm = localtime(&t); int year = _tm->tm_year+1900; int month = _tm->tm_mon+1; int date = _tm->tm_mday; int hh = _tm->tm_hour; int mm = _tm->tm_min; int ss = _tm->tm_sec; sprintf(tmp,"%04d%02d%02d%02d%02d%02d%02d%02d", year,month,date,hh-1,0,0,year,month,date,hh,mm,ss); return string(tmp); }
//打印指定时间
string
warn_export::timetoStr(long timeStamp){ time_t t = timeStamp; tm *_tm = gmtime(&t); int year = _tm->tm_year+1900; int month = _tm->tm_mon+1; int date = _tm->tm_mday; int hh = _tm->tm_hour; //int mm = _tm->tm_min; //int ss = _tm->tm_sec; char tmp[64]; sprintf(tmp,"%04d-%02d-%02d(%02d:%02d:%02d - %02d:%02d:%02d)", year,month,date,hh-1,0,0,hh,0,0); return string(tmp); }

 

posted @ 2018-01-09 14:39  luckyFireHao  阅读(5777)  评论(0编辑  收藏  举报