Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


get time -> day/mo/year etc

This topic is 5508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was trying to write some code that converted the thing returned by timeGetTime() into the format "of dd/mm/yy hh:mm:ss", but then I found out that timeGetTime wraps around every 50 days or something, and is not what I wanted at all. What is the function in c++ that returns the number of milliseconds since jan1, 1970? I think I can easily get the current date out of that. Or is there an even easier way to determine the current day in c++?

Share this post

Link to post
Share on other sites
The time function:


time, _time64

Get the system time.

time_t time(
time_t *timer
__time64_t _time64(
__time64_t *timer
Pointer to the storage location for time.
Return Value
Return the time in elapsed seconds. There is no error return.

A call to time or _time64 can fail, however, if the date passed to the function is:

Before midnight, January 1, 1970.
After 19:14:07, January 18, 2038, UTC (using time and time_t).
After 23:59:59, December 31, 3000, UTC (using _time64 and __time64_t).

Share this post

Link to post
Share on other sites
call the time function to get the number of seconds since 1970..

then call localtime to get a tm structure. from here you can use printf to format it however you want.

"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!