static std::string get_format_time(int64_t ms) { int microsec = ms%1000; time_t t(ms / 1000); struct tm *p = localtime(&t); char s[100]; int pos = strftime(s, sizeof(s), "%Y%m%d-%H:%M:%S", p); sprintf(&s[pos], ".%03d", microsec); return std::string(s); } int main() { std::cout << get_format_time(1604992150091) << std::endl; return 0; }