Jelajahi Sumber

Added getLocalTime console function

Add getLocalTime console function so that script has access to the local
time.
Nathan Bowhay 10 tahun lalu
induk
melakukan
7ef3a64957
1 mengubah file dengan 20 tambahan dan 0 penghapusan
  1. 20 0
      Engine/source/app/game.cpp

+ 20 - 0
Engine/source/app/game.cpp

@@ -202,6 +202,26 @@ DefineConsoleFunction( getRealTime, S32, (), , "()"
    return Platform::getRealMilliseconds();
    return Platform::getRealMilliseconds();
 }
 }
 
 
+ConsoleFunction( getLocalTime, const char *, 1, 1, "Return the current local time as: weekday month day year hour min sec.\n\n"
+                "Local time is platform defined.")
+{
+   Platform::LocalTime lt;
+   Platform::getLocalTime(lt);
+
+   static const U32 bufSize = 128;
+   char *retBuffer = Con::getReturnBuffer(bufSize);
+   dSprintf(retBuffer, bufSize, "%d %d %d %d %02d %02d %02d",
+      lt.weekday,
+      lt.month + 1,
+      lt.monthday,
+      lt.year + 1900,
+      lt.hour,
+      lt.min,
+      lt.sec);
+
+   return retBuffer;
+}
+
 ConsoleFunctionGroupEnd(Platform);
 ConsoleFunctionGroupEnd(Platform);
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------