C++日期和时间戳相互转换的代码
2018-07-20 来源:open-open
日期字符转化成时间戳
时间戳转化成日期
时间戳转化成日期
/*
@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;
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Java上传下载功能的实现
下一篇:C++自定义数组长度的快速排序
最新资讯
热门推荐