VC++获取系统当前时间并显示
VC++6.0 获取系统时间 并输入格式化字符串
CTime tm = CTime::GetCurrentTime();
CString strtm= tm.Format("%Y-%m-%d %H:%M:%S");
AfxMessageBox(strtm);
1、定义一个CTime类对象 CTime time;
2、 得到当前时间 time = CTime::GetCurrentTime();
3、GetYear( ),GetMonth( ), GetDay( ), GetHour( ), GetMinute( ), GetSecond( ), GetDayOfWeek( ) 返回整型(int)对应项目
4、将当前时间格式化 CString date = time.Format("%Y-%m-%d %H:%M:%S %W-%A");
例子:
1
2
3
|
CTime ct = CTime::GetCurrentTime(); //获取当前时间
CString str = ct.Format( "%Y-%m_%d %H-%M-%S" ); //格式化时间
|
结果:str="2006-04-23 15-21-30"
日期格式化参数说明:
%a
Abbreviated weekday name
星期(缩写英文),如Fri;
%A
Full weekday name
星期(全写英文),如Friday
%b
Abbreviated month name
月份(缩写英文),如Oct
%B
Full month name
月份(全写英文),如 October
%c
Date and time representation appropriate for locale
月/日/年 时:分:秒,如 10/13/06 19:17:17
%d
Day of month as decimal number (01 – 31)
一月中的日期(1 ~ 31)
%H
Hour in 24-hour format (00 – 23)
时(24小时制)(0 ~ 23)
%I
Hour in 12-hour format (01 – 12)
时(12小时制)(0 ~ 12)
%j
Day of year as decimal number (001 – 366)
一年当中的第几天,(1 ~ 366)
%m
Month as decimal number (01 – 12)
月份(数字 1 ~ 12)
%M
Minute as decimal number (00 – 59)
分(0 ~ 59)
%p
Current locale's A.M./P.M. indicator for 12-hour clock
12小时中的A M/PM指示,或者AM,或者PM
%S
Second as decimal number (00 – 59)
秒(0 ~ 59)
%U
Week of year as decimal number, with Sunday as first day of week (00 – 53)
一年中的第几周,星期日作为每周的第一天(0 ~ 53)
%w
Weekday as decimal number (0 – 6; Sunday is 0)
星期(数字表示,0 ~ 6,0代表星期日)
%W
Week of year as decimal number, with Monday as first day of week (00 – 53)
一年中的第几周,星期一作为每周的第一天(0 ~ 53)
%x
Date representation for current locale
月/日/年,%c的前半段
%X
Time representation for current locale
时/分/秒,%c的后半段
%y
Year without century, as decimal number (00 – 99)
年份(不带世纪,如 06)
%Y
Year with century, as decimal number
年份(带世纪,如 2006)
%z, %Z
Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
时区名称或缩写,如果时区未知,此字符为空,如“中国标准时间”
%%
Percent sign
两个百分号格式化以后代表一个%
============================================================
下面是另一个例子:
1
2
3
4
5
6
7
8
9
|
// Example for CTime::Format and CTime::FormatGmt
CTime t( 1999, 3, 19, 22, 15, 0 );
// 10:15 PM March 19, 1999
CString s = t.Format( "%A, %B %d, %Y" );
ATLASSERT( s == "Friday, March 19, 1999" );
|
补充说明:“#”标志的含义
① %#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#% ——“#” 被忽略
② %#c —— 把%c中的数字变成英文,再在前面加上星期, 如:“Tuesday, March 14, 1995, 12:41:29”.
③ %#x —— 把%x中的数字变成英文,再在前面加上星期,如:Tuesday, March 14, 1995
④ %#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y —— 如果开 头为0,去掉开头的0
VC++获取系统当前时间并显示相关推荐
- VC获取系统空闲时间
LASTINPUTINFO lpi; lpi.cbSize = sizeof(lpi); GetLastInputInfo(&lpi); int iTime ...
- 笔记1:VC获取系统时间的方法
笔记1:VC 获取系统时间的方法 推荐的获取方法 获取时间方法种类 各种获取时间方法详解 方法1:time_t变量 和 time(time_t*)方法 方法2:system(" time&q ...
- VC++ 获取系统时间的方法汇总
1.使用CTime类(获取系统当前时间,精确到秒) ? 1 2 3 4 5 6 CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();/ ...
- 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- android service 样例(电话录音和获取系统当前时间)
关于android service 的具体解释请參考: android四大组件--android service具体解释.以下将用两个实例具体呈现Android Service的两种实现. 一个是st ...
- 获取系统当前日期时间
今天学习了一个获取系统当前日期时间的方式. 代码如下: #include <iostream> #include <ctime> using namespace std; in ...
- php中跟时间有关的处理(时区设置,计算时间差,获取系统当前时间)
1.修改时区 背景 :保存到Navicat中的时间和本地系统时间相差8小时 原因:在app/config下的app.php中有一行 ['timezone' => 'UTC',} 规定的是时区默认 ...
- C++ 获取系统当前时间
C++ 获取系统当前时间 c++ time函数_C++的日期和时间函数 获取系统当前时间实例 大体思路 具体使用与解析 四.回顾与梳理 c++ time函数_C++的日期和时间函数 C++ 标准库没有 ...
- java生成当前时间int_java获取系统当前时间
本文收集整理关于java获取系统当前时间的相关议题,使用内容导航快速到达. 内容导航: Q1:java中怎样获得系统当前时间? public static String nowTime() { Cal ...
最新文章
- java 文件夹删除_java创建删除文件及文件夹大全
- SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-003-@Conditional根据条件生成bean及处理profile...
- POJ1580 水题,积累!
- Golang map 如何进行删除操作?
- 配置基于python的VIM环境
- java 重载 equals_实现Student类的equals重载函数
- 使用 telnet 命令 查看端口的开放、可用情况
- 20220906_C52单片机学习笔记 | LED闪烁
- mysql经纬度 微信_微信获取用户的经纬度
- js代码编写新年倒计时
- 关于E-R(实体-联系)图
- 【知识图谱】实践篇——基于知识图谱的《红楼梦》人物关系可视化及问答系统实践:part6基于图谱的问答实现
- 10大免费视频素材网站
- python实现直播功能_Python实现直播推流效果
- html页面中文显示乱码问题
- CAD中如何查看要素高程
- c语言循环中按键跳出,C语言跳出循环
- 雷电模拟器安装magisk和Xposed
- 【Word】利用域代码快速实现基于书签的交叉引用
- 求斜率,针对非线性传感器分段计算斜率,套入程序中。
热门文章
- 学 Python 必看的书单汇总
- DELL XPS15 9570 32GB内存升级记
- echarts 饼图 中间 画圈 + 文字
- 老男孩教育Linux运维培训32期决心书
- 埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛E题小Y吃苹果
- AliOS Things物联网操作系统
- SVG公众号排版 | 多段自动展开过程会卡住,无法完全展开!
- 检测到可疑访问 php,php.net被Chrome/Firefox浏览器标注为可疑站点
- XP SP3 IIS 5.1版本安装包下载地址和XP SP3 IIS 5.1版本安装方法
- 宇宙学colossus库介绍