gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
请举例使用std::chrono获取当前时间并且用毫秒为单位显示
- User
请举例使用std::chrono获取当前时间并且用毫秒为单位显示
- Assistant
下面是使用std::chrono获取当前时间并以毫秒为单位显示的示例:
#include <iostream> #include <chrono> int main() { // 获取当前时间 auto now = std::chrono::system_clock::now(); // 将时间点转换为毫秒数 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count(); std::cout << "当前时间(毫秒): " << millis << std::endl; return 0; }这个程序使用std::chrono库的system_clock类获取当前时间,然后将其转换为毫秒数并以此显示。