Game Development Community

dev|Pro Game Development Curriculum

Time Function

by Joe Gamer · 02/22/2008 (10:58 am) · 1 comments

This is an additon to Richards post at

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11576

in main.cc
add

#include after other includes
then add this console function

ConsoleFunction( getSysDateTimeFromFormat,const char*, 2, 2, "Get the time formated from the argument string i.e %d %d %04d")
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );

char *ret = Con::getReturnBuffer(256);
dSprintf(ret,256, argv[1],(timeinfo->tm_year + 1900), timeinfo->tm_mon,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
return ret;
}


so for UTC call like this
echo(getSysDateTimeFromFormat("%04d-%02d-%02dT%02d:%02d:%02d.00Z"))

About the author

Recent Blogs


#1
11/24/2009 (12:51 am)
This seems to be windows-compatible only... (references VC includes)

Why not:

ConsoleFunction( getSysDateTimeFromFormat, const char*, 2, 2, "Get the time formated from the argument string i.e %04d-%02d-%02dT%02d:%02d:%02d.00Z")
{
Platform::LocalTime lt;
Platform::getLocalTime(lt);

char *ret = Con::getReturnBuffer(256);
dSprintf(ret, 256, argv[1], lt.year, lt.month, lt.monthday, lt.hour, lt.min, lt.sec);
return ret;
}