Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to get the time in c++ as string

string currentDateToString()
{
    time_t now = time(0);
    tm *ltm = localtime(&now);

    string dateString = "", tmp = "";
    tmp = numToString(ltm->tm_mday);
    if (tmp.length() == 1)
        tmp.insert(0, "0");
    dateString += tmp;
    dateString += "-";
    tmp = numToString(1 + ltm->tm_mon);
    if (tmp.length() == 1)
        tmp.insert(0, "0");
    dateString += tmp;
    dateString += "-";
    tmp = numToString(1900 + ltm->tm_year);
    dateString += tmp;
    dateString += " ";
    tmp = numToString(ltm->tm_hour);
    if (tmp.length() == 1)
        tmp.insert(0, "0");
    dateString += tmp;
    dateString += ":";
    tmp = numToString(1 + ltm->tm_min);
    if (tmp.length() == 1)
        tmp.insert(0, "0");
    dateString += tmp;
    dateString += ":";
    tmp = numToString(1 + ltm->tm_sec);
    if (tmp.length() == 1)
        tmp.insert(0, "0");
    dateString += tmp;

    return dateString;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Header for INT_MIN 
Cpp :: c++ get line 
Cpp :: find kth max and min element in an array 
Cpp :: char to integer c++ 
Cpp :: what is - in c++ 
Cpp :: string vector to string c++ 
Cpp :: cpp getter as const 
Cpp :: integer to char c++ 
Cpp :: how to split string into words c++ 
Cpp :: C++ float and double Different Precisions For Different Variables 
Cpp :: iterate over map c++ 
Cpp :: c++ builder 
Cpp :: how to get hcf of two number in c++ 
Cpp :: Max element in an array with the index in c++ 
Cpp :: matrix dynamic memory c++ 
Cpp :: c++ clip values 
Cpp :: c++ convert const char* to int 
Cpp :: attention nlp 
Cpp :: c for loop decrement 
Cpp :: access last element of set c++ 
Cpp :: cpp get exception type 
Cpp :: exception handling class c++ 
Cpp :: add matic mainnet to metamask mobile 
Cpp :: c++ fill two dimensional array 
Cpp :: loop execution decending order in c 
Cpp :: create a vector of size n in c++ 
Cpp :: remove comments c++ 
Cpp :: read a whole line from the input 
Cpp :: how to extract a folder using python 
Cpp :: size of unordered_set 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =