I did not find any solution which give the only date. I found the solution but all are complex and we have to parse the array and separate the date from time
Asked
Active
Viewed 2,556 times
3 Answers
2
Try to this
#include <iostream>
#include <iomanip>
#include <ctime>
int main()
{
auto t = std::time(nullptr);
auto tm = *std::localtime(&t);
std::cout << std::put_time(&tm, "%d-%m-%Y %H-%M-%S") << std::endl;
}

Haresh Shyara
- 1,826
- 10
- 13
1
If you run the following code, today then you will find the current date in following format.
04/14/15
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
char c[9];
_strdate_s(c);
cout<<c<<endl;
return 0;
}

sss
- 31
- 1
- 2
-
3Code snippets doesn't support c++, yet. – keyser Apr 14 '15 at 13:33
-
1_strdate_s is not a function included in the c++ standard. it is only supported by the library shipped with visual studio as far as i know. – smerlin Apr 14 '15 at 13:34
0
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t now = time(0);
tm *ltm = localtime(&now);
cout << "Year: "<< 1900 + ltm->tm_year << endl;
cout << "Month: "<< 1 + ltm->tm_mon<< endl;
cout << "Day: "<< ltm->tm_mday << endl;
}

utarid
- 1,642
- 4
- 24
- 38