time


1. Current Time and Date

#include <iostream>
#include <ctime>

int main() {
  time_t t = time(nullptr);
  struct tm *now = localtime(&t);
  std::cout << "Current time and date: " << now->tm_mday << '/'
            << (now->tm_mon + 1) << '/' << (now->tm_year + 1900) << ' '
            << now->tm_hour << ':' << now->tm_min << ':' << now->tm_sec << std::endl;
  return 0;
}

2. Sleep for a Specific Duration

#include <iostream>
#include <thread>

int main() {
  std::cout << "Sleeping for 5 seconds..." << std::endl;
  std::this_thread::sleep_for(std::chrono::seconds(5));
  std::cout << "Done sleeping." << std::endl;
  return 0;
}

3. Measure Execution Time

4. Limit Execution Time

5. Retry with Exponential Backoff

6. Timed Mutex Lock

7. Scheduled Tasks

8. Timed Event Loop

9. Rate Limiter

10. Deadline Timer

11. Performance Counter

12. Time Zone Conversion

13. Time Leap Detection

14. Precise Time Measurement

15. Wait for a Specific Time

16. Date and Time Formatting