C++语言Windows显示时间

 时间:2024-10-12 00:07:51

1、//程序运行截图,以及源码。using namespace std;#include "挢旗扦渌;iomanip"#include "iostream"#include "windows.h"#include "winbase.h"int time_data(){ SYSTEMTIME time; GetLocalTime( &time ); cout<<setfill('0'); cout<<time.wYear<<"年"<<time.wMonth<<"月"<<time.wDay<<"日"; cout<<setw(2)<<time.wHour<<":"<<setw(2)<<time.wMinute<<":"<<setw(2)<<time.wSecond; cout<<" 星期"; switch(time.wDayOfWeek) { case 0:cout<<"日";break; case 1:cout<<"一";break; case 2:cout<<"二";break; case 3:cout<<"三";break; case 4:cout<<"四";break; case 5:cout<<"五";break; case 6:cout<<"六";break; } return 0;}int main(){ for(;;) { time_data(); for(int sum=0;sum<=265;sum++) cout<<"\b"; Sleep(1000); } }

C++语言Windows显示时间

2、下面开始分析这些源码。

C++语言Windows显示时间

3、SYSTEMTIME time; GetLocalTime( &time );定义和获取系统时间的Windows API

C++语言Windows显示时间

4、cout<<setfill('0');C++语言的cout填充函数,当前语句填充字符为“0”。

C++语言Windows显示时间

5、输出Windows系统时间,格式:年月日 时分秒

C++语言Windows显示时间

6、switch(time.wDayOfWeek)switch分支语句作用将time.wDayOfWeek对象的数值转化为对应的文字。

C++语言Windows显示时间

7、外层for循环是让时间显示;内层for循环是刷新时间;time_data();调用上面的模块 Sleep(1000); 延迟作用,挂起程序。

C++语言Windows显示时间
  • Python编程:怎么使用Counter类计数字符串对象
  • 俄洛伊怎么打狗熊
  • 如何正确实现c语言strcpy函数
  • 建立二叉树的代码c语言
  • 英雄联盟不能打开商店、黑屏解决方法!
  • 热门搜索
    环境保护手抄报资料 年俗年韵年文化手抄报 好看的手抄报花边 关于梦想的手抄报图片 三月文明礼貌月手抄报 我的家乡手抄报图片 国史党史手抄报资料 名胜古迹手抄报 有关节约用水的手抄报 感恩自然手抄报