I need to calculate timestamp in milliseconds for two weeks old date from the current date.
As of now this is the way I am calculating current timestamp in milliseconds -
struct timeval tp;
gettimeofday(&tp, NULL);
uint64_t current_ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
Now I am not sure how do I get the timestamp in milliseconds for two weeks back from the current date? I am interested in making a function which returns me the timestamp in milliseconds for two weeks back from the current date.
I recently started working with C++ so not sure what is the right way to check out a timestamp in milliseconds for two weeks old. I will be running this code on Ubuntu 12.04.
Update:-
Below is the code I have -
#include <ctime>
#include <chrono>
#include <iostream>
int main()
{
const auto now = std::chrono::system_clock::now();
auto twoWeeks = std::chrono::hours(24 * 14);
auto lastTwoWeeks = now - twoWeeks;
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>\
(lastTwoWeeks.time_since_epoch()).count();
std::cout << "Time stamp in milliseconds since UNIX epoch start: "\
<< millis << std::endl;
return 0;
}