I have a method below which will accept oldTimestamp
as the input parameter which is uint64_t
... Now I need to apply a formula on the above oldTimestamp
and whenever I apply that formula, I always get 0
as start
value.
And also I try to get the current timestamp
in milliseconds in the same method which is long int
data type (not sure whether this is right datatype) and whenever I apply the same formula again on the currentTimestamp
, I always get end
value as 0
as well...
Below is my method -
void getRecord(uint64_t oldTimestamp) {
int start = (oldTimestamp / (60 * 60 * 1000 * 24)) % 14;
cout<<"START: " << start <<endl; // this always print out as 0..?
struct timeval tp;
gettimeofday(&tp, NULL);
long int currentTimestamp = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
int end = (currentTimestamp / (60 * 60 * 1000 * 24)) % 14;
cout<<"END: " << end <<endl; // this always print out as 0 as well..?
}
Is there anything wrong I am doing here?
Might be, I am using wrong Data Type for currentTimestamp and oldTimestamp and I should not use int
for start
and end
?
Update:-
Something like this will be fine?
void getRecord(uint64_t oldTimestamp) {
uint64_t start = (oldTimestamp / (60 * 60 * 1000 * 24)) % 14;
cout<<"START: " << start <<endl;
struct timeval tp;
gettimeofday(&tp, NULL);
uint64_t currentTimestamp = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
uint64_t end = (currentTimestamp / (60 * 60 * 1000 * 24)) % 14;
cout<<"END: " << end <<endl;
}