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); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM