For a tm Strict
Loading current time into a tm struct – see here
Get The Current Time And Display In A String
#include <sys/time.h>
static int seconds_last = 99;
char TimeString[128];
timeval curTime;
gettimeofday(&curTime, NULL);
if (seconds_last == curTime.tv_sec)
return;
seconds_last = curTime.tv_sec;
strftime(TimeString, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec));
timeval and gettimeofday gives you tvsec and tv_usec which is the number of seconds the Epoch. You need to use local time to convert into the current time.
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.