 <p>You can use the code snippet given below as it will serve your purpose. Here use <strong>time.h</strong> header file for required <strong>localtime()</strong> function and then using the <strong>strftime()</strong> function with required parameters will give the output and it returns it as a string.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;time.h&gt; std::string current_date(); std::string current_time(); int main(){ std::cout&lt;&lt;"Current date =&gt; "&lt;&lt;current_date()&lt;&lt;"\n"; std::cout&lt;&lt;"Current time =&gt; "&lt;&lt;current_time()&lt;&lt;"\n"; } std::string current_date(){ time_t now = time(NULL); struct tm tstruct; char buf[40]; tstruct = *localtime(&amp;now); //format: day DD-MM-YYYY strftime(buf, sizeof(buf), "%A %d/%m/%Y", &amp;tstruct); return buf; } std::string current_time(){ time_t now = time(NULL); struct tm tstruct; char buf[40]; tstruct = *localtime(&amp;now); //format: HH:mm:ss strftime(buf, sizeof(buf), "%X", &amp;tstruct); return buf; } </code></pre>