C++日期和时间戳相互转换的代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

日期字符转化成时间戳
时间戳转化成日期
           /*
                 @param       date
                 @param       formart  of date
                 @return      time_t
                 @author      yangqijun@outlook.com
               */
              time_t strtotime(char* const date,char* const format="%Y%m%d%H%M%S")
              {
                      struct tm tm;
                      strptime(date,format, &tm) ;
                      time_t ft=mktime(&tm);
                      return ft;
              }
 
 
 
string   timetodate(time_t const timer)
              {
                      struct tm *l=localtime(&timer);
 
                      char buf[128];
                      snprintf(buf,sizeof(buf),"%04d-%02d-%02d %02d:%02d:%02d",l->tm_year+1900,l->tm_mon+1,l->tm_mday,l->tm_hour,l->tm_min,l->tm_sec);
                      string s(buf);
                      return s;
 
 
              }