VC++6.0 MFC COleDateTime 格式化

今天排查一个头疼的问题,某软件在某些电脑上能正常查询数据,而在另外一些电脑上查不到数据,经测试发现,问题的原因是在某些电脑上无法正确地对日期进行格式化,导致查不到数据。

目标:从日期框获取时间, COleDateTime类格式化输出字符串

C++不熟悉,折腾了半天,总算找到了方法,代码如下:

	COleDateTime m_tty;
	m_tty=m_DateE1.GetDate(); //m_DateE1是DateTimePicker控件
	CString StDate = m_tty.Format(_T("%Y%m%d")); //输出 20190518

问题解决。顺便列一下格式化的规则:

  
CodeReplacement string
%aAbbreviated weekday name in the locale
%AFull weekday name in the locale
%bAbbreviated month name in the locale
%BFull month name in the locale
%cDate and time representation appropriate for locale
%CThe year divided by 100 and truncated to an integer, as a decimal number (00−99)
%dDay of month as a decimal number (01 - 31)
%DEquivalent to %m/%d/%y
%eDay of month as a decimal number (1 - 31), where single digits are preceded by a space
%FEquivalent to %Y-%m-%d
%gThe last 2 digits of the ISO 8601 week-based year as a decimal number (00 - 99)
%GThe ISO 8601 week-based year as a decimal number
%hAbbreviated month name (equivalent to %b)
%HHour in 24-hour format (00 - 23)
%IHour in 12-hour format (01 - 12)
%jDay of the year as a decimal number (001 - 366)
%mMonth as a decimal number (01 - 12)
%MMinute as a decimal number (00 - 59)
%nA newline character (\n)
%pThe locale's A.M./P.M. indicator for 12-hour clock
%rThe locale's 12-hour clock time
%REquivalent to %H:%M
%SSecond as a decimal number (00 - 59)
%tA horizontal tab character (\t)
%TEquivalent to %H:%M:%S, the ISO 8601 time format
%uISO 8601 weekday as a decimal number (1 - 7; Monday is 1)
%UWeek number of the year as a decimal number (00 - 53), where the first Sunday is the first day of week 1
%VISO 8601 week number as a decimal number (00 - 53)
%wWeekday as a decimal number (0 - 6; Sunday is 0)
%WWeek number of the year as a decimal number (00 - 53), where the first Monday is the first day of week 1
%xDate representation for the locale
%XTime representation for the locale
%yYear without century, as decimal number (00 - 99)
%YYear with century, as decimal number
%zThe offset from UTC in ISO 8601 format; no characters if time zone is unknown
%ZEither the locale's time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
%%Percent sign

MS文档链接:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=vs-2017

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鹰信息技术服务部

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值