易采站长站为您分析C++实现当前时间动态显示的方法,涉及C++时间操作及Sleep方法的使用,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了C++实现当前时间动态显示的方法。。具体如下:
- /* 24-06-10 10:44 动态显示时间 但不是最优的 功能很单一
- 本程序关键是对时钟函数的使用 **tm结构定义了 年、月、日、时、分、秒、星期、当年中的某一天、夏令时
- **用localtime获取当前系统时间,该函数将一个time_t时间转换成tm结构表示的时间,函数原型: struct tm * localtime(const time_t *)
- **使用gmtime函数获取格林尼治时间,函数原型: struct tm * gmtime(const time_t *) 包含的头文件是time.h */
- //struct tm { // int tm_sec; /* seconds after the minute - [0,59] */
- // int tm_min; /* minutes after the hour - [0,59] */ // int tm_hour; /* hours since midnight - [0,23] */
- // int tm_mday; /* day of the month - [1,31] */ // int tm_mon; /* months since January - [0,11] */
- // int tm_year; /* years since 1900 */ // int tm_wday; /* days since Sunday - [0,6] */
- // int tm_yday; /* days since January 1 - [0,365] */ // int tm_isdst; /* daylight savings time flag */
- // }; #include <iostream>
- #include <time.h> #include "dos.h"
- #include <windows.h> using namespace std;
- int main() {
- char *myweek[]={"日","一","二","三","四","五","六"}; time_t nowtime; //typedef long time_t;在编译器定义的头文件中
- nowtime = time(NULL); //获取当前时间 此时它是用一个长整形表示的 struct tm *local; /*时间结构体变量*/
- local = localtime(&nowtime); //获取当前系统时钟 while (1)










