导航
  • 主页
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

CDateTimeCtrl如何设置时间,非当前时间?

wanyhong 2010-08-10 10:17:57
如题,目的就是给时间空间设置一个非当前时间,比如设置成 2009-01-11
SetDlgItemText(IDC_DATETIMEPICKER1,"1975-07-01"); 这样不行
使用MSDN上SetTime的方法也不行,直接把MSDN上的例子拷过去执行也不能设置啊?
...全文
606 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Eleven 2010-08-10

CDateTimeCtrl* pTime = (CDateTimeCtrl*)GetDlgItem(IDC_DATETIMEPICKER1);
ASSERT(pTime);
CTime timeTime(2009, 1, 11, 0, 0, 0);
pTime->SetTime(&timeTime);
回复
starytx 2010-08-10
更正一下:
CDateTimeCtrl time;
COleDateTime t;
t.PraseDateTime(strdate);
time.SetTime(t);
回复
starytx 2010-08-10
CDateTimeCtrl time; // 为你的时间控件绑定的变量
COleDateTime t;
t.ParseDateTime(strdate);
m_date=t;
回复
wanyhong 2010-08-10
这个方法试过了,还是更新不上去啊 ,强制刷新窗体也不行,还有什么办法大哥?
回复
oyljerry 2010-08-10
CDateTimeCtrl* pCtrl = (CDateTimeCtrl*) GetDlgItem(IDC_DATETIMEPICKER1);
ASSERT(pCtrl != NULL);

// Set with CTime.
CTime timeTime(1998, 4, 3, 0, 0, 0);
VERIFY(pCtrl-> SetTime(&timeTime));

// Set with a COleDateTime object.
COleDateTime oletimeTime(1998, 4, 3, 0, 0, 0);
VERIFY(pCtrl-> SetTime(oletimeTime));

// Set using SYSTEMTIME.
SYSTEMTIME sysTime;
memset(&sysTime, 0, sizeof(sysTime));
sysTime.wYear = 1998;
sysTime.wMonth = 4;
sysTime.wDay = 3;
VERIFY(pCtrl-> SetTime(&sysTime));
回复
wanyhong 2010-08-10
不是设置时间显示格式 大哥,是给设置个时间,不如说我代码里设置要显示的时间是1999-12-10,但是总是显示今天的时间2010-08-10
回复
oyljerry 2010-08-10
CDateTimeCtrl::SetFormat("yyyy-MM");

"d" The one- or two-digit day.
"dd" The two-digit day. Single-digit day values are preceded by a zero.
"ddd" The three-character weekday abbreviation.
"dddd" The full weekday name.
"h" The one- or two-digit hour in 12-hour format.
"hh" The two-digit hour in 12-hour format. Single-digit values are preceded by a zero.
"H" The one- or two-digit hour in 24-hour format.
"HH" The two-digit hour in 24-hour format. Single-digit values are preceded by a zero.
"m" The one- or two-digit minute.
"mm" The two-digit minute. Single-digit values are preceded by a zero.
"M" The one- or two-digit month number.
"MM" The two-digit month number. Single-digit values are preceded by a zero.
"MMM" The three-character month abbreviation.
"MMMM" The full month name.
"t" The one-letter AM/PM abbreviation (that is, AM is displayed as "A").
"tt" The two-letter AM/PM abbreviation (that is, AM is displayed as "AM").
"yy" The last two digits of the year (that is, 1996 would be displayed as "96").
"yyyy" The full year (that is, 1996 would be displayed as "1996").
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……