wxWidgets中wxDateTime与wxString的互操作

本文详细介绍了wxDateTime类中日期时间的操作方法,包括格式化、解析日期和时间,以及日期时间的比较与计算。通过实例展示了如何获取当前日期时间、格式化为字符串并转换为日期和时间格式,同时提供了日期时间解析的例子。
void datetest()
 {
 wxDateTime now=wxDateTime::Now();
 wxString date1=now.Format();
 wxString date2=now.Format(wxT("%X"));
 wxString date3=now.Format(wxT("%x"));
 
 //下面代码只显示日期部分
 cout<<"wxDateTime now=wxDateTime::Now():"<<wxDateTime::Now().FormatDate()<<endl;
 cout<<"now.Format():"<<date1<<endl;//日期时间
 cout<<"now.Format(wxT(\"%X\")):"<<date2<<endl;//时间
 cout<<"now.Format(wxT(\"%x\")):"<<date3<<endl;//日期
 
 //有趣的ParseDateTime()
 cout<<"\n\nwxDateTime::ParseDateTime():"<<endl;
 
 //tomorrow 是什么日子?
 cout<<"tomorrow:"<<endl;
 wxDateTime tomorrow;
 tomorrow.ParseDateTime(wxT("tomorrow 11:00am"));
 cout<<"Tomorrow is "<<tomorrow.Format()<<endl;
 
 //五一又是什么日子?
 cout<<"The Labor Day test:"<<endl;
 wxDateTime laborday;
 laborday.ParseDate(wxT("May 1st"));
 cout<<"The Labor Day is "<<laborday.Format()<<endl;
 
 //至于wxDateSpan,用法非常直白,仅举一例,顺便一提Format的另一种格式:
 wxDateSpan span(0,1);
 wxDateTime then=now.Add(span);
 cout<<then.Format(wxT("%B %d %Y"))<<endl;
 
 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值