Hi I'm trying to do a getTime()
function that returns uint16_t
in C.
I do can successfully get an array of chars now
Here's my code for a output of array of chars.
Say today is Dec 9 2014
the output will be 091214
So how can i make the output a uint16_t
type?
in this case can i keep the "0"
in 091214
if it's a uint16_t
type?
char *getT(){
struct tm *tm;
time_t t;
static char str_date[10];
t = time(NULL);
tm = localtime(&t);
strftime(str_date, sizeof(str_date), "%d%m%y", tm);
return str_date;}
and there's another approach i modified from the code i found on-line.
this one returns the sum of 9+12+14
....
uint16_t getD(){
struct tm *tm_time;
time_t ti;
//const time_t create_time;
uint16_t t, d;
ti = time(NULL);
tm_time = localtime(&ti);
t = (tm_time->tm_sec >> 1) + (tm_time->tm_min << 5) + (tm_time->tm_hour << 11);
d = (tm_time->tm_mday>>1) + ((tm_time->tm_mon+1) << 5) + ((tm_time->tm_year-80) << 9);
printf("%d %d %d %d \n",d,tm_time->tm_mday>>1,tm_time->tm_mon<<5,(tm_time->tm_year-80)<<9);
return d;}