I need a function or library to get the current system time in milliseconds from 1/1/1970 (C++) ?
I need to get a unsigned double number containing the milliseconds from 1/1/1970.
The operating system is Windows.
ADDITIONAL INFO:
Need to synchronize the server application and the client. The client is the master. The client tells the server when he needs to do something. After that the server runs on its own. I am sending the time stamp from the client that contains the current system time down to the millisecond level. The Server once received this message must do the same thing. He must get the time stamp and the difference will be the number of milliseconds to adjust its timeline. This is a matter of how to synchronize to process to do some related work at the same time.
DO NOT WANT TO USE BOOST IF IT IS POSSIBLE !
You can use GetSystemTimeAsFileTime
to get the current time as a FILETIME
. Create a SYSTEMTIME
representing your desired epoch (1/1/1970) and call SystemTimeToFileTime
to convert it to a FILETIME
. Subtract the two FILETIME
s and scale to your desired accuracy (from 100ns units to 1ms units).
This will give you the current UTC time. If you need the local time, you'll need to convert to local time using e.g. SystemTimeToTzSpecificLocalTime
.