c++ vs中如何操作时间

其他教程   发布日期:2023年06月25日   浏览次数:361

这篇文章主要介绍“c++ vs中如何操作时间”,在日常操作中,相信很多人在c++ vs中如何操作时间问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”c++ vs中如何操作时间”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

代码如下:

  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4. int main()
  5. {
  6. cout << "Hello World!" << endl;
  7. const time_t now = time(NULL);
  8. cout << "时间戳:" << now << endl;
  9. struct tm systime;
  10. localtime_s(&systime, &now);
  11. // 输出 tm 结构的各个组成部分
  12. cout << "年: " << 1900 + systime.tm_year << endl;
  13. cout << "月: " << 1 + systime.tm_mon << endl;
  14. cout << "日: " << systime.tm_mday << endl;
  15. cout << "时间: " << systime.tm_hour << ":" << systime.tm_min << ":" << systime.tm_sec << endl;
  16. }

结果:

  1. Hello World!
  2. 时间戳:1649294557
  3. 年: 2022
  4. 月: 4
  5. 日: 7
  6. 时间: 9:22:37

以上就是c++ vs中如何操作时间的详细内容,更多关于c++ vs中如何操作时间的资料请关注九品源码其它相关文章!