Game Development Community

Getting date and time from Windows

by Daniel Portugal de Lourenço · in Torque Game Builder · 11/25/2007 (5:59 am) · 5 replies

Hi there.

How do I get the real date and time from Windows?

The funcion getRealTime() is only for the game time, and getSimTime() is for ticks. Is there a native function to get date and time from Windows? In case there isn't, does anyone know how to do it?

Thanks

#1
11/25/2007 (6:26 am)
I added the following to main.cc, under the console function for getRealTime:

ConsoleFunction( getLocalTime, const char *, 1, 1, "Return the current local time as: month day year hour min sec.\n\nLocal time is platform defined.")
{
	Platform::LocalTime lt;
   Platform::getLocalTime(lt);

   char *retBuffer = Con::getReturnBuffer(128);
   dSprintf(retBuffer, 128, "%d %d %d %02d %02d %02d",
        lt.month + 1,
        lt.monthday,
        lt.year + 1900,
        lt.hour,
        lt.min,
        lt.sec);

   return retBuffer;
}

That should give you everything you need...
#2
11/25/2007 (6:44 am)
Thanks, Eric!

I am not experienced with programming, so I just want to be sure: if I change a .cc file, do I have do re-compile the engine? (I copied your code and apparently torque didn't read it)
#3
11/25/2007 (7:53 am)
I do need to recompile.

I'm downloading Visual Studio and will search for tutorials on how to do it. :)
#4
11/25/2007 (8:16 am)
Visual studio express 2005 is still free I think.
Add the code posted above, and then build click Build Solution.
Just open the T2d SDK.sln located in \engine\compilers\VisualStudio 2005.

Maybe you've figured all of this out already, but if you didn't, I hope I helped a tiny bit.

:)
#5
11/25/2007 (5:33 pm)
Thanks, Simon. Your information was helpful bacause it assured me it should be a simple process. I was getting errors when trying to complile (windows.h and objbase.h could not be found).

I followed the tutorial on how to create a debug version of torque, and the paths for the SDK are different there. So I just changed the path for libraries and include files and it worked.

c:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib


And the code works perfectly, it even separates each field by spaces, and that helps when retrieving the information.

Great!! XD