使用给定格式将毫秒转换为持续时间
Convert Milliseconds to Duration with the given format
对于给定的 203443
毫秒 持续时间(这是 3
分钟,23
秒和 443
毫秒) ,例如
这样的模式
This took about' m 'minutes and' s 'seconds.
会产生以下结果
格式化输出:
This took about 3 minutes and 23 seconds.
格式时间戳与当前日期时间不同。是否有任何 C++ 标准库(在 C++14 下)或我可以遵循的解决方案。我是 C++ 新手。
#include <chrono>
#include <iostream>
int
main()
{
using namespace std::chrono;
auto d = 203443ms;
auto m = duration_cast<minutes>(d);
d -= m;
auto s = duration_cast<seconds>(d);
std::cout << "This took about " << m.count() << " minutes and "
<< s.count() << " seconds.\n";
}
对于给定的 203443
毫秒 持续时间(这是 3
分钟,23
秒和 443
毫秒) ,例如
This took about' m 'minutes and' s 'seconds.
会产生以下结果 格式化输出:
This took about 3 minutes and 23 seconds.
格式时间戳与当前日期时间不同。是否有任何 C++ 标准库(在 C++14 下)或我可以遵循的解决方案。我是 C++ 新手。
#include <chrono>
#include <iostream>
int
main()
{
using namespace std::chrono;
auto d = 203443ms;
auto m = duration_cast<minutes>(d);
d -= m;
auto s = duration_cast<seconds>(d);
std::cout << "This took about " << m.count() << " minutes and "
<< s.count() << " seconds.\n";
}