Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

DP QC STRFTIME

From Quake Wiki

Builtin definitions:

string(float uselocaltime, string format, ...) strftime = #478;

Provides the ability to get the local (in your timezone) or world (Universal Coordinated Time) time as a string using the formatting of your choice:

example: "%Y-%m-%d %H:%M:%S" (result looks like: 2007-02-08 01:03:15)

note: "%F %T" gives the same result as "%Y-%m-%d %H:%M:%S" (ISO 8601 date format and 24-hour time)

For more format codes please see http://www.daemon-systems.org/man/strftime.3.html or google for strftime 3 and look for the man pages for this standard C function.

Practical uses:

  • Changing day/night cycle (shops closing, monsters going on the prowl) in an RPG, for this you probably want to use s = strftime(TRUE, "%H");hour = ftos(s);
  • Printing current date/time for competitive multiplayer games, such as the beginning/end of each round in real world time.
  • Activating eastereggs in singleplayer games on certain dates.

Note:

  • Some codes such as %x and %X use your locale settings and thus may not make sense to international users, it is not advisable to use these as the server and clients may be in different countries.
  • If you display local time to a player, it would be a good idea to note whether it is local time using a string like "%F %T (local)", and otherwise use "%F %T (UTC)".
  • Be aware that if the game is saved and reloaded a week later the date and time will be different, so if activating eastereggs in a singleplayer game or something you may want to only check when a level is loaded and then keep the same easteregg state throughout the level so that the easteregg does not deactivate when reloading from a savegame (also be aware that precaches should not depend on such date/time code because reloading a savegame often scrambles the precaches if so!).
  • This function can return a NULL string (you can check for it with if (!s)) if the localtime/gmtime functions returned NULL in the engine code, such as if those functions don't work on this platform (consoles perhaps?), so be aware that this may return nothing.