Skip to content

Instantly share code, notes, and snippets.

@jxq0
Last active January 2, 2016 13:49
Show Gist options
  • Save jxq0/8313041 to your computer and use it in GitHub Desktop.
Save jxq0/8313041 to your computer and use it in GitHub Desktop.
c++ date trans
time_t StrToStamp(const string &str, const string &fmt)
{
struct tm tmInfo;
strptime(str.c_str(), fmt.c_str(), &tmInfo);
return mktime(&tmInfo);
}
int TransDateStr(const string &src, const string &fmt_src, string &dst, const string &fmt_dst)
{
struct tm tmInfo;
strptime(src.c_str(), fmt_src.c_str(), &tmInfo);
char buff[32];
strftime(buff, 32, fmt_dst.c_str(), &tmInfo);
dst = string(buff);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment