system-clock

Android - Get current time without dependency on device's clock

孤街醉人 提交于 2019-11-26 23:36:20
问题 I've noticed that System.currentTimeMillis() time is device dependent. If I change the time on the device's clock, this method will return a different answer. For example: If the real time now is 10:00, and I change the clock on my device to 9:30, then System.currentTimeMillis() will return the 9:30 time (in milliseconds..). I've also tried this answer and some other answers, but didn't find anything useful. I should state that my app works mostly offline. Is there a way to get the real

Why is CLOCKS_PER_SEC not the actual number of clocks per second?

二次信任 提交于 2019-11-26 17:32:02
问题 I have just written this short C++ program to approximate the actual number of clock ticks per second. #include <iostream> #include <time.h> using namespace std; int main () { for(int i = 0; i < 10 ; i++) { int first_clock = clock(); int first_time = time(NULL); while(time(NULL) <= first_time) {} int second_time = time(NULL); int second_clock = clock(); cout << "Actual clocks per second = " << (second_clock - first_clock)/(second_time - first_time) << "\n"; cout << "CLOCKS_PER_SEC = " <<