Need help, no idea on how to do

Hi,

I created a simply code of getting the current date. Now, I noticed that after compling the result is 3012013. But, what I want is 30/01/2013. How do I do this...
Here is the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <ctime>

using namespace std;

int main( )
{
   // current date based on current system
   time_t now = time(0);

   tm *ltm = localtime(&now);

   cout << ltm->tm_mday << 01 + ltm->tm_mon << 1900 + ltm->tm_year << endl;
  
}



And one more thing. How do I loop it that the day will be change to the next day.


Appreciate the assistances.

Thank you,


Marcus
Last edited on
But, what I want is 30/01/2013. How do I do this...
Like so:
cout << ltm->tm_mday << '/' << 01 + ltm->tm_mon << '/' << 1900 + ltm->tm_year << endl;

And one more thing. How do I loop it that the day will be change to the next day.
What do you mean? loop until tm_mday changes?



Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
#include <iostream>
using namespace std;

int main()
{
cout << __DATE__;

return 0;
}

simply can better go like this....
> cout << __DATE__;

__DATE__ is the date on which the file was compiled.


> How do I loop it that the day will be change to the next day.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <ctime>
#include <iostream>

int main()
{
    std::time_t now = std::time(0) ;
    std::tm* ptm = std::localtime( &now ) ;

    for( int i = 0 ; i < 50 ; ++i ) // print the next 50 days
    {
        char time_str[128] ;
        std::strftime( time_str, sizeof(time_str), "%d/%b/%Y", ptm ) ;
        std::cout << time_str << '\n' ;
        ptm->tm_mday += 1 ;
        now = std::mktime(ptm) ;
        ptm = std::localtime( &now ) ;
    }
}

coder777 (2516) Jan 30, 2013 at 4:58pm
But, what I want is 30/01/2013. How do I do this...
Like so:
cout << ltm->tm_mday << '/' << 01 + ltm->tm_mon << '/' << 1900 + ltm->tm_year << endl;

And one more thing. How do I loop it that the day will be change to the next day.
What do you mean? loop until tm_mday changes?



Please use code tags: Your code
See: http://www.cplusplus.com/articles/z13hAqkS/

Noted on these info.
Yes, I would like to loop the day up 1 month
Coder777
JLBorges
venkyHyd

Thank you for the replies. Appreciate it much
Topic archived. No new replies allowed.