Get timestamp

    0

    0

    Giovanny Gongora

    Codiga's C++ Recipes

    Get timestamp from localtime

    #include <iostream>
    using namespace std;
    
    std::string get_timestamp() {
      time_t now = time(NULL);
      struct tm* ltm = localtime(&now);
      char buffer[80];
      strftime(buffer, 80, "%Y-%m-%d-%H-%M-%S", ltm);
      return std::string(buffer);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.