Assuming you did correctly initialize time
, it's because you're overflowing when multiplying time->tv_sec
by 1000. In your case, it's 1.4 billion already, and the signed multiplication you're doing ends up overflowing at 2.1 billion or so. Use 64-bit multiplication to get around it:
uint64_t millis = (time->tv_sec * (uint64_t)1000) + (time->tv_usec / 1000);
Make sure to print it out using a reasonable format.