I did not find a nice way for getting year month day etc…
so I wrote my one function:
int get_date(int option)
{
int value =0;
char thetime[32] = {0};
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
switch (option)
{
case 1: /*YEAR*/
strftime(thetime, sizeof thetime, "%Y", timeinfo);
break;
case 2: /*MONTH*/
strftime(thetime, sizeof thetime, "%m", timeinfo);
break;
case 3: /*DAY*/
strftime(thetime, sizeof thetime, "%d", timeinfo);
break;
case 4: /*HOUR*/
strftime(thetime, sizeof thetime, "%I", timeinfo);
break;
case 5: /*MINUTES*/
strftime(thetime, sizeof thetime, "%M", timeinfo);
break;
case 6: /*SECONDS*/
strftime(thetime, sizeof thetime, "%S", timeinfo);
break;
}
value = atoi(thetime);
return value;
}
nice and easy
by the way its quite odd that you cant just get this values
from timeinfo like timeinfo.tm_hour cause it trow:
request for member `tm_hour’ in something not a structure or union