为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > CTime格式化

CTime格式化

2018-03-16 4页 doc 16KB 14阅读

用户头像

is_668482

暂无简介

举报
CTime格式化CTime格式化 用CTime类得到当前日期、时间、星期,并格式化输出 ? 定义一个CTime类对象 CTime time; ? 得到当前时间 time = CTime::GetCurrentTime(); ? GetYear( ),GetMonth( ), GetDay( ), GetHour( ), GetMinute( ), GetSecond( ), GetDayOfWeek( ) 返回整型(int)对应项目 ? 将当前时间格式化 CString date = time.Format("%Y-%m-%d ...
CTime格式化
CTime格式化 用CTime类得到当前日期、时间、星期,并格式化输出 ? 定义一个CTime类对象 CTime time; ? 得到当前时间 time = CTime::GetCurrentTime(); ? GetYear( ),GetMonth( ), GetDay( ), GetHour( ), GetMinute( ), GetSecond( ), GetDayOfWeek( ) 返回整型(int)对应项目 ? 将当前时间格式化 CString date = time.Format("%Y-%m-%d %H:%M:%S %W-%A"); 说明: 1) 结果为:2006-10-13 17:23:47 41-Friday 2) 格式符号说明 %a —— 星期(缩写英文),如Fri; %A —— 星期(全写英文),如Friday %b —— 月份(缩写英文),如Oct %B —— 月份(全写英文),如 October %c —— 月/日/年 时:分:秒,如 10/13/06 19:17:17 %d —— 日期(1 ~ 31) %H —— 时(24小时制)(0 ~ 23) %I —— 时(12小时制)(0 ~ 12) %j —— 一年当中的第几天,(1 ~ 366) %m —— 月份(数字 1 ~ 12) %M —— 分(0 ~ 59) %p —— 12小时中的A M/PM指示,或者AM,或者PM %S —— 秒(0 ~ 59) %U —— 一年中的第几周,星期日作为每周的第一天(0 ~ 53) %w —— 星期(数字表示,0 ~ 6,0代表星期日) %W —— 一年中的第几周,星期一作为每周的第一天(0 ~ 53) %x —— 月/日/年,%c的前半段 %X —— 时/分/秒,%c的后半段 %y —— 年份(不带世纪,如 06) %Y —— 年份(带世纪,如 2006) %z,%Z —— 时区名称或缩写,如果时区未知,此字符为空,如“中国标准时间” %% —— % “#”标志的含义: ? %#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 CSting ---------------------->CTime CString timestr = "2000年04月05日"; int year,month,day; BYTE tt[5]; //get year memset(tt, 0, sizeof(tt)); tt[0] = timestr[0]; tt[1] = timestr[1]; tt[2] = timestr[2]; tt[3] = timestr[3]; year= atoi((char *)tt); //get month memset(tt, 0, sizeof(tt)); tt[0] = timestr[6]; tt[1] = timestr[7]; month = atoi((char *)tt); //get day memset(tt, 0, sizeof(tt)); tt[0] = timestr[10]; tt[1] = timestr[11]; CTime time(year,month,day,0,0,0); ---- or ----------- CString timestr = "2000年04月05日"; int a,b,c ; sscanf(timestr.GetBuffer(timestr.GetLength()),"%d年%d 月%d日",&a,&b,&c); CTime time(a,b,c,0,0,0); --------or - --------------------- CString s("2001-8-29 19:06:23"); int nYear, nMonth, nDate, nHour, nMin, nSec; sscanf(s, "%d-%d-%d %d:%d:%d", &nYear, &nMonth, &nDate, &nHour, &nMin, &nSec); CTime t(nYear, nMonth, nDate, nHour, nMin, nSec);
/
本文档为【CTime格式化】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索