Created
April 7, 2015 20:27
-
-
Save vampy/b1bcca0fe7267bf59658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctime> | |
#include <string> | |
class Time | |
{ | |
public: | |
static std::string getTime() // in HH:MM::SS | |
{ | |
std::time_t t = std::time(nullptr); | |
std::tm *tm = std::localtime(&t); | |
const int size = 16; | |
char buffer[size]; | |
if (std::strftime(buffer, size, "%H:%M:%S",tm) == 0) | |
{ | |
throw std::runtime_error("Error trying to getTime"); | |
} | |
return std::string(buffer); | |
} | |
static std::string getDate() // in day:month:year | |
{ | |
std::time_t t = std::time(nullptr); | |
std::tm *tm = std::localtime(&t); | |
const int size = 16; | |
char buffer[size]; | |
if (std::strftime(buffer, size, "%d:%m:%Y",tm) == 0) | |
{ | |
throw std::runtime_error("Error trying to getDate"); | |
} | |
return std::string(buffer); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment