0

I am trying to get current raw time (the one that is NOT human readable) in my simple while loop. I searched time_t clock cycle period but I couldn't find any information about it.

1st issue: Does anyone know the clock cycle period of time_t in C++?

2nd issue: When I print time ltime, it look same all the time.

time_t ltime;
while (count <= 1000) {
  time( & ltime); //I expect this to get current time in every cycle
  cout << "Current time " << ltime << endl;
  count++;
}

I already checked this link but it does not give information about clock period.

Deniz
  • 378
  • 3
  • 16

1 Answers1

1

Use std::chrono::high_resolution_clock::now()

Edit:

Use std::system_clock::now() and std::chrono::system_clock::to_time_t()

yumetodo
  • 1,147
  • 7
  • 19
  • In actual long code I put it in uint32_t map, so its type is not suitable that is why I chose time_t – Deniz Sep 19 '19 at 07:41
  • thank you I did `uint32_t time = static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count());` – Deniz Sep 19 '19 at 08:12
  • you should not represent time with 32bit. consider the year 2038 problem. – yumetodo Sep 29 '19 at 04:37