get std::chrono::duration from std::chrono::point_time
时间: 2023-09-12 08:12:40 浏览: 47
Unfortunately, there is no direct way to obtain a `std::chrono::duration` from a `std::chrono::point_time`. However, you can calculate the duration between two `std::chrono::point_time` instances using the `std::chrono::duration_cast` function. Here's an example:
```c++
#include <chrono>
int main() {
using namespace std::chrono;
// Create two point_time instances
auto start = system_clock::now();
auto end = system_clock::now() + seconds(30);
// Calculate the duration between the two point_time instances
auto duration = duration_cast<seconds>(end - start);
// Print the duration in seconds
std::cout << duration.count() << " seconds\n";
return 0;
}
```
In this example, we create two `system_clock::now()` instances to represent the start and end times. We then calculate the duration between them using the `duration_cast` function, which converts the difference between the two `point_time` instances into a `duration` of seconds. Finally, we print the duration in seconds using the `count` function.