I've a long
as: 1459791437
and I want to transform it in this format: YYYYMMDD,HH
.
I don't know how to convert that long
in a struct tm
, I need that conversion to use the function: strftime
.
Here you can see what I want to do:
void find_date(long timestamp, int *date, int *hour){
char buf[20];
struct tm *time_struct = magic_function(timestamp);
strftime(buf, sizeof(buf), "%Y%m%d,%H", time_struct);
printf("Time: %s", buf);
}
I've tried this solution but it doesn't print anything:
void find_date(long timestamp, int *date, int *hour){
char buf[20];
struct tm *timeinfo;
/* Conversion to time_t as localtime() expects a time_t* */
time_t epoch_time_as_time_t = timestamp;
/* Call to localtime() now operates on time_t */
timeinfo = localtime (&epoch_time_as_time_t);
strftime (buf, sizeof(buf), "%Y%m%d,%H", timeinfo);
printf("Test: %s", buf);
}
What I cannot do is the struct tm *magic_function(long)
, could anyone help me?