12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #ifndef TRM_TOOLS_H
- #define TRM_TOOLS_H
- #include <sstream>
- #include <string>
- #include <time.h>
- #include <iomanip>
- namespace tools{
- struct time_tools{
-
- static std::string time_t2string(const time_t& t)
- {
- struct tm* p = nullptr;
- char buf[30] = {'\0'};
- if(t<=0){
- return "0";
- }
- p = localtime(&t);
- snprintf(buf,
- sizeof(buf),
- "%04d-%02d-%02d %02d:%02d:%02d",
- p->tm_year+1900,
- p->tm_mon+1,
- p->tm_mday,
- p->tm_hour,
- p->tm_min,
- p->tm_sec
- );
- return std::string(buf);
- }
- };
- struct string_tools{
- static const std::string format13str(const uint8_t& l,const uint32_t& r)
- {
- //std::stringstream ss;
- //ss<<std::setw(3)<<std::setfill('0')<<l<<std::setw(10)<<std::setfill('0')<<r;
- //std::string result = ss.str();
-
- //return result;
- char sql[15] = {0};
- snprintf(sql, 15,"%03d%010d", l, r);
- return std::string(sql);
- }
- };
- };
- #endif
|