In std C++,How to get the Current time?

C

CppNewer

And Is there any class or method to manipulate Date or Time In standard C++?
-------Thank all
 
I

Ian Collins

Christopher said:
include the <ctime> header

look up:

time_t
GetTime()
tm
LocalTime()
or just a reference for <ctime>
Now of the above are standard C++ library functions, <ctime> defines
localtime, and gmtime which should serve the OP's requirements.
 
S

Sam

It's not C++, but rather POSIX.

See the time() and/or gettimeofday() man pages.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD4DBQBHo9Psx9p3GYHlUOIRApdLAJj5dJogNCIp+maGs/ld8MsCPX3qAJ9M0RVo
x+76Y+N92QcHEOkTL7K1QA==
=Jpce
-----END PGP SIGNATURE-----
 
C

Christopher

Now of the above are standard C++ library functions, <ctime> defines
localtime, and gmtime which should serve the OP's requirements.

time_t is standard and is defined in <ctime>
tm is standard and is also defined in <ctime>

However, I agree neither of these are standard _functions_, but they
are standard types that standard functions make use of.

LocalTime() is standard if you change to lowercase spelling, but I
didn't tell him to compile it, I told him to look it up.


I do admit, I mistook time() for GetTime() and GetTime() is not a
standard function. Use time() instead.
Better is to consult your reference for the <ctime> header, like I
said.
 
S

Sam

Ian said:
What isn't C++?

"Date or Time". There's no such thing called "Date or Time" in the C++
language.
time() is C++.

No, it's not. The latest C++ language speficiation, as defined by ISO/IEC
14882:2003, does not define any function called "time()".


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHo9n8x9p3GYHlUOIRAnbIAJ9+InZ6Z+npYfqlkON7Mhlh59AWaQCfRFDr
4Ekp0RZmjmV+FmKA4eDvyTM=
=fepq
-----END PGP SIGNATURE-----
 
I

Ian Collins

Sam said:
No, it's not. The latest C++ language speficiation, as defined by
ISO/IEC 14882:2003, does not define any function called "time()".
See 20.5.
 
J

Jack Klein

-------Thank all

Make up your mind, do you want to get the time or manipulate it? And
what do you mean by "manipulate" it?

C++ provides functions to get the current time and data, inherited
from C. It provides more inherited functions to convert the time into
text in various ways, for writing to a file or display.

It does not provide any functions for changing a computer's date or
time.

Consult your compiler's manual, on-line help, or man pages and look at
the function defined in <ctime> or <time.h>.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
R

red floyd

Sam said:
"Date or Time". There's no such thing called "Date or Time" in the C++
language.


No, it's not. The latest C++ language speficiation, as defined by
ISO/IEC 14882:2003, does not define any function called "time()".

It's incorporated by reference from ISO/IEC 9899:1990.
 
J

James Kanze

"Date or Time". There's no such thing called "Date or Time" in
the C++ language.

No, it's not. The latest C++ language speficiation, as defined
by ISO/IEC 14882:2003, does not define any function called
"time()".

Funny, it's in my copy of the standard. Both the 1998 version
and the 2003 version (and the latest draft for the next
version).

Posix does extend it, of of course---gettimeofday() is Posix,
and not pure C++---but time(), localtime(), gmttime(), etc. are
part of the C++ standard.
application_pgp-signature_part
1KDownload

On the other hand, such add-ons are allowed in news according to
the NNTP standard.
 

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

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,516
Latest member
TobiasAxf

Latest Threads

Top