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[64];
    int pos = strftime(s, sizeof(s), "%Y%m%d-%H:%M:%S", p);

    sprintf(&s[pos], ".%03d", microsec);

    return std::string(s);
}

static std::string get_curr_format_time() {
    struct  timeval tv;
    gettimeofday(&tv, 0x0);

    int microsec = tv.tv_usec/1000;
    time_t t(tv.tv_sec);
    struct tm *p = localtime(&t);
    char s[64];
    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;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
猜你喜欢
  • 2022-12-23
  • 2021-10-18
  • 2021-11-30
  • 2022-12-23
  • 2022-02-08
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案