CTime类format的使用

STM32F103-时钟树 STM32F1 时钟树 参考:《【野火®】零死角玩转STM32—F103指南者》 时钟源 HSI:高速内部时钟,RC振荡器,频率为8MHz HSE:高速外部时钟,可接石英/陶瓷谐振器,或者接外部时钟源,频率范围为4MHz~16MHz LSI:低速内部时钟,RC振荡器,频率为40kHz LSE:低速外部时钟,接频率为32.768kHz的石英晶体 LSI可以用于驱动独立看门狗和通过程序选择驱动RTC。RTC用于从停机/待机模式下自动唤醒系统。LSE也可用来通过程序选择驱动RTC。 内部即指芯片 阅读详情
 
        
       使用CTime类可以很方便地取得当前系统时间并转换为各种格式
      
The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a percent sign ( %). Characters that do not begin with % are copied unchanged to strDest. The LC_TIME category of the current locale affects the output formatting of strftime.(For more information on LC_TIME, see setlocale.) The formatting codes for strftime are listed below:
%a
Abbreviated weekday name
%A
Full weekday name
%b
Abbreviated month name
%B
Full month name
%c
Date and time representation appropriate for locale
%d
Day of month as decimal number (01 – 31)
%H
Hour in 24-hour format (00 – 23)
%I
Hour in 12-hour format (01 – 12)
%j
Day of year as decimal number (001 – 366)
%m
Month as decimal number (01 – 12)
%M
Minute as decimal number (00 – 59)
%p
Current locale's A.M./P.M. indicator for 12-hour clock
%S
Second as decimal number (00 – 59)
%U
Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w
Weekday as decimal number (0 – 6; Sunday is 0)
%W
Week of year as decimal number, with Monday as first day of week (00 – 53)
%x
Date representation for current locale
%X
Time representation for current locale
%y
Year without century, as decimal number (00 – 99)
%Y
Year with century, as decimal number
%z, %Z
Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
%%
Percent sign

As in the printf function, the # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows.
Format codeMeaning
%#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#%# flag is ignored.
%#cLong date and time representation, appropriate for current locale. For example: "Tuesday, March 14, 1995, 12:41:29".
%#xLong date representation, appropriate to current locale. For example: "Tuesday, March 14, 1995".
%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#YRemove leading zeros (if any).
Requirements
RoutineRequired headerCompatibility
strftime<time.h>ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
wcsftime<time.h> or <wchar.h>ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

 
 
Example

 
// crt_times.c
                /* This program demonstrates these time and date functions:
                *      _time64         _ftime64        _ctime64     asctime
                *      _localtime64    _gmtime64       _mktime64    _tzset
                *      _strtime        _strdate        strftime
                *
                * Also the global variable:
                *      _tzname
                */
                
                #include <time.h>
                #include <stdio.h>
                #include <sys/types.h>
                #include <sys/timeb.h>
                #include <string.h>
                
                int main()
                {
                char tmpbuf[128], ampm[] = "AM";
                __time64_t ltime;
                struct __timeb64 tstruct;
                struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };
                
                /* Set time zone from TZ environment variable. If TZ is not set,
                * the operating system is queried to obtain the default value 
                * for the variable. 
                */
                _tzset();
                
                /* Display operating system-style date and time. */
                _strtime( tmpbuf );
                printf( "OS time:tttt%sn", tmpbuf );
                _strdate( tmpbuf );
                printf( "OS date:tttt%sn", tmpbuf );
                
                /* Get UNIX-style time and display as number and string. */
                _time64( &ltime );
                printf( "Time in seconds since UTC 1/1/70:t%ldn", ltime );
                printf( "UNIX time and date:ttt%s", _ctime64( &ltime ) );
                
                /* Display UTC. */
                gmt = _gmtime64( &ltime );
                printf( "Coordinated universal time:tt%s", asctime( gmt ) );
                
                /* Convert to time structure and adjust for PM if necessary. */
                today = _localtime64( &ltime );
                if( today->tm_hour >= 12 )
                {
                strcpy( ampm, "PM" );
                today->tm_hour -= 12;
                }
                if( today->tm_hour == 0 )  /* Adjust if midnight hour. */
                today->tm_hour = 12;
                
                /* Note how pointer addition is used to skip the first 11 
                * characters and printf is used to trim off terminating 
                * characters.
                */
                printf( "12-hour time:tttt%.8s %sn",
                asctime( today ) + 11, ampm );
                
                /* Print additional time information. */
                _ftime64( &tstruct );
                printf( "Plus milliseconds:ttt%un", tstruct.millitm );
                printf( "Zone difference in hours from UTC:t%un", 
                tstruct.timezone/60 );
                printf( "Time zone name:tttt%sn", _tzname[0] );
                printf( "Daylight savings:ttt%sn", 
                tstruct.dstflag   "YES" : "NO" );
                
                /* Make time for noon on Christmas, 1993. */
                if( _mktime64( &xmas ) != (__time64_t)-1 )
                printf( "Christmastttt%sn", asctime( &xmas ) );
                
                /* Use time structure to build a customized time string. */
                today = _localtime64( &ltime );
                
                /* Use strftime to build a customized time string. */
                strftime( tmpbuf, 128,
                "Today is %A, day %d of %B in the year %Y.n", today );
                printf( tmpbuf );
                }
Sample Output

 
OS time:                                14:15:49
                OS date:                                02/07/02
                Time in seconds since UTC 1/1/70:       1013120149
                UNIX time and date:                     Thu Feb 07 14:15:49 2002
                Coordinated universal time:             Thu Feb 07 22:15:49 2002
                12-hour time:                           02:15:49 PM
                Plus milliseconds:                      455
                Zone difference in hours from UTC:      8
                Time zone name:                         Pacific Standard Time
                Daylight savings:                       NO
                Christmas                               Sat Dec 25 12:00:00 1993
                
                

 简单点的如下:
 CString msg1="aaaaaaaaaaa";
    
    KillTimer(1);   
 
  CTime t = CTime::GetCurrentTime();
  char szTime[8];
  int nHour = t.GetHour();
  int nMinute = t.GetMinute();
  int nSecond = t.GetSecond();
    wsprintf(szTime, "%02i:%02i:%02i", nHour, nMinute,nSecond);//分秒一般习惯用两位表
  m_edit1=szTime;
  UpdateData (FALSE);
  SetTimer(1, 1000,NULL);
  msg1=t.Format("%d-%m-%y");   //可以看到format的功能
   MessageBox(msg1);

CTime::Format参数使用说明 十分详细的列举了CTime::Format的参数使用说明,比msdn详细点,希望对初学者有帮助 立即下载

相关推荐

嵌入式常用通信协议 #概述

嵌入式通信协议

AFK3060的博客 2117

CTime类操作

CTime CTime time = CTime::GetCurrentTime(); int Year = time.GetYear(); int Month = time.GetMonth(); int Day = time.GetDay(); int Hour = time.GetH

1238

FPGA实战:用DDR3和乒乓操作解决视频帧撕裂问题(附Verilog代码)

本文详细介绍了如何利用DDR3内存和乒乓操作架构解决FPGA视频处理中的帧撕裂问题。通过多帧缓存原理、AXI接口配置和自适应乒乓操作设计,有效隔离读写操作,确保视频流稳定传输。文章包含Verilog代码实现和性能优化技巧,适用于工业相机、医疗影像等高速视频处理场景。

m2n3b4v5c6的博客 290

CTime::Format

CTime/COleDateTime::Format方法的使用 CTime ct = CTime::GetCurrentTime(); CString str = ct.Format("%Y-%m_%d %H-%M-%S"); 输出为:str="2006-04-23 15-21-3...

weixin_34096182的博客 370

qt实现程序密钥注册功能,MD5加密+AES加密,并实现一台电脑系统一个密钥

qt实现了一个给自己软件加密的功能。 原理是: 需要被注册的软件第一次运行的时候,在系统的注册表里面注册一个键值,如下: 这个值作为生成密钥的用户识别号,然后生成密钥文件key.db,把这个key.db文件放到软件执行目录下,即可完成软件的注册并正常使用软件。 软件第一次打开的界面及密钥生成工具软件界面如下: 将密钥生成工具软件生成的key.db放到软件执行目录下之后,软件即可正常使用,如下图: 代码使用了MD5加密 外加 AES加密, 解密和加密的核心代码如下: QSt.

weixin_43935474的博客 4129

全志 mipi屏幕和触摸驱动调试记录

mipi屏幕与触摸调试记录

u011996684的博客 3221

VC++中CTime类format的使用

CTime类format的使用                 使用CTime类可以很方便地取得当前系统时间并转换为各种格式        The format argument consists of one or more codes; as in p

Rya的专栏 6556

WVP+ZLM国标平台实战:从设备注册失败到视频播放黑屏,我遇到的5个典型问题与解法

部署WVP+ZLM国标视频平台时,设备注册失败、视频播放黑屏等问题常常让运维人员头疼不已。本文将基于真实运维场景,剖析五个最具代表性的故障案例,提供从网络配置到版本兼容性的全链路解决方案。

weixin_33178839的博客 362

VC++中CTime类Format参数详解

CTime类通过Format可以格式化输出日期时间信息,通过控制Format的参数我们可以实现各种各样的日期时间格式输出,要想随心所欲的控制输出的格式,就需要搞清楚各个参数的意义,下面通过实例来说明各个Format参数的意义。   假设CTime对象当前的日期时间为:2011-4-17 14:32:18 星期日 英文表示为:Sunday, April 17, 2011 14:32:18,下表中列...

housecarl的博客 2072

用KalmanNet搞定非线性状态估计:当卡尔曼滤波遇上神经网络

本文深入探讨了KalmanNet如何将神经网络与卡尔曼滤波结合,以解决非线性状态估计中的模型失配和噪声不确定性问题。通过保留经典滤波框架并用RNN学习卡尔曼增益,该方法在无人机导航、机器人定位等场景中实现了模型驱动与数据驱动的优势互补,提升了估计的鲁棒性和灵活性。

mango的博客 312

RT-DETR改进策略【独家融合改进】| SPD-Conv+PPA 再次提升模型针对小目标的特征提取能力

SPD-Conv是一种新的 CNN 构建模块,用于替代传统 CNN 架构中使用的步长卷积(strided convolution)和池化(pooling)层,它由空间到深度(Space-to-depth,SPD)层和非步长卷积(non - strided convolution)层组成。

Limiiiing的博客 1155

CTime 类的 Format函数注意事项

CTime 类 的Format函数和CDateTimeCtrl类的SetFormat函数的参数形式是一样的。原文链接:https://blog.youkuaiyun.com/u012782049/article/details/26808773。根据相关的文档使用相应的函数。MM表示用两位来表示月。(月用大写的MM表示)yyyy表示用四位数来表示年。

zxf347085420的博客 1078

Autosar PNC网络管理配置(1)-基于ETAS软件

Autosar PNC网络管理配置(1)-基于ETAS软件

赞的博客 2732

CTime类format的使用【转贴】

使用CTime类可以很方便地取得当前系统时间并转换为各种格式        The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a percent sign (%). Characters that do not begin with % are

一兰阳光 1991

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

CTime 类 的Format函数和CDateTimeCtrl类的SetFormat函数参数区别

今天 调程序的时候开始一直以为两者的dai

u012782049的专栏 1457

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

[转]VC++中CTime类Format参数详解

CTime类通过Format可以格式化输出日期时间信息,通过控制Format的参数我们可以实现各种各样的日期时间格式输出,要想随心所欲的控制输出的格式,就需要搞清楚各个参数的意义,下面通过实例来说明各个Format参数的意义。   假设CTime对象当前的日期时间为:2011-4-17 14:32:18 星期日 英文表示为:Sunday, April 17, 2011 14:32:18,下表中列

天网冰封专栏 410

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

【转】VC++中CTime类format的使用 COleDateTime

<br />在使用CTime 和COleDateTime 类的时候,不太清楚Format的格式化字符串<br />尤其是显示天 --%d (小写的d)<br />%m(小写的)    月份<br />%M(大写的)    分钟<br /> <br />转自下面<br />http://blog.youkuaiyun.com/Rya/archive/2008/04/29/2342939.aspx<br /> <br />CTime类format的使用 <br />         <br />       使用CTime

为了理想而奋斗 1719
上一篇: 这些歌, 请戴上耳机, 调大音量, 一个人听 ,全世界 都是你的!!!!!
下一篇: CListCtrl使用技巧
CButtonST
博客等级 码龄16年 42粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值