Date

P

Paul Selibas

Greetings, i know to get all the dates/times one would use the header ctime
or time.h.
Can some one then direct me in the right direction to actually get the date
or anything.

Many thanks!
 
J

John Harrison

Paul Selibas said:
Greetings, i know to get all the dates/times one would use the header ctime
or time.h.
Can some one then direct me in the right direction to actually get the date
or anything.

Many thanks!

Time functions are tricky to handle. Something like this should work
(untested)

#include <time.h>

tm time = *localtime(time(0));
cout << "The date is " << time.tm_mday << '/' << time.tm_mon + 1 << '/' <<
time.tm_year + 1900;

This prints the date British style (i.e. day / month / year).

john
 
J

John Harrison

Time functions are tricky to handle. Something like this should work
(untested)

#include <time.h>

tm time = *localtime(time(0));
cout << "The date is " << time.tm_mday << '/' << time.tm_mon + 1 << '/' <<
time.tm_year + 1900;

This prints the date British style (i.e. day / month / year).

john

Apologies, I said they were tricky. Try this

time_t t = time(0);
tm time = *localtime(&t);
cout << "The date is " << time.tm_mday << '/' << time.tm_mon + 1 << '/' <<
time.tm_year + 1900;

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,126
Messages
2,570,753
Members
47,313
Latest member
SamualGriz

Latest Threads

Top