First thing to say, i'm an absolute noob in programming so it might be a very simple thing and i'm not getting it.
I want to know how much time has passed since the beginning of the day and to do that i used the time()
function.
I then want to print it and here is my problem: with the first printf the variable seconds
is printed correctly but in the second printf
(where I print mills
and seconds
) it gives me a wrong output.
The code:
#include <stdio.h>
#include <time.h>
int main(void) {
long long int mills, seconds;
mills = time(NULL);
printf("Mills: %i\n", mills );
seconds = mills / 1000;
//here the variable is printed correctly
printf("Seconds: %i\n", seconds );
//here mills gets printed correctly but seconds gets printed as 0
printf("Milliseconds since midnight: %i\nSeconds since midnight: %i\n", mills, seconds);
return 0;
}
The output:
Mills: 1486143107
Seconds: 1486143
Milliseconds since midnight: 1486143107
Seconds since midnight: 0
Why is the variable printed correctly the first time but not the second time? Shouldn't it be always the same?