First of I do not want to use #include <ctime>
and time(0);
the time(0); is with ctime. What I want is if say the time is 10:13:40:23 AM I would get the value of 23. I looked around the web for a while and could not find anything besides ctime, but ctime is for the system time in milliseconds meaning that the value is really high. Another example would be 12:56:30:192 PM and I would get the value of 192. thanks for any help :).
With C++ 11, using std::chrono library.
#include <iostream>
#include <chrono>
int main()
{
auto now = std::chrono::system_clock::now();
std::chrono::milliseconds ms_since_epoch = std::chrono::duration_cast< std::chrono::milliseconds >(now.time_since_epoch());
std::chrono::seconds seconds_since_epoch = std::chrono::duration_cast< std::chrono::seconds >(now.time_since_epoch());
std::cout << (ms_since_epoch - seconds_since_epoch).count() << std::endl;
return 0;
}
On seconds thought, modulo 1000 would have done the same as subtracting the seconds. Anyway, given that the epoch is canonical (has 00 for seconds and 000 for milliseconds), that part of it is indeed the actual milliseconds measurement of the now moment.