还是看代码说话。其中ParseDate()/ParseTime()/ParseDateTime最有趣了。
1 void datetest()
2 {
3 wxDateTime now=wxDateTime::Now();
4 wxString date1=now.Format();
5 wxString date2=now.Format(wxT("%X"));
6 wxString date3=now.Format(wxT("%x"));
7
8 //下面代码只显示日期部分
9 cout<<"wxDateTime now=wxDateTime::Now():"<<wxDateTime::Now().FormatDate()<<endl;
10 cout<<"now.Format():"<<date1<<endl;//日期时间
11 cout<<"now.Format(wxT(\"%X\")):"<<date2<<endl;//时间
12 cout<<"now.Format(wxT(\"%x\")):"<<date3<<endl;//日期
13
14 //有趣的ParseDateTime()
15 cout<<"\n\nwxDateTime::ParseDateTime():"<<endl;
16
17 //tomorrow 是什么日子?
18 cout<<"tomorrow:"<<endl;
19 wxDateTime tomorrow;
20 tomorrow.ParseDateTime(wxT("tomorrow 11:00am"));
21 cout<<"Tomorrow is "<<tomorrow.Format()<<endl;
22
23 //五一又是什么日子?
24 cout<<"The Labor Day test:"<<endl;
25 wxDateTime laborday;
26 laborday.ParseDate(wxT("May 1st"));
27 cout<<"The Labor Day is "<<laborday.Format()<<endl;
28
29 //至于wxDateSpan,用法非常直白,仅举一例,顺便一提Format的另一种格式:
30 wxDateSpan span(0,1);
31 wxDateTime then=now.Add(span);
32 cout<<then.Format(wxT("%B %d %Y"))<<endl;
33
34 }
2 {
3 wxDateTime now=wxDateTime::Now();
4 wxString date1=now.Format();
5 wxString date2=now.Format(wxT("%X"));
6 wxString date3=now.Format(wxT("%x"));
7
8 //下面代码只显示日期部分
9 cout<<"wxDateTime now=wxDateTime::Now():"<<wxDateTime::Now().FormatDate()<<endl;
10 cout<<"now.Format():"<<date1<<endl;//日期时间
11 cout<<"now.Format(wxT(\"%X\")):"<<date2<<endl;//时间
12 cout<<"now.Format(wxT(\"%x\")):"<<date3<<endl;//日期
13
14 //有趣的ParseDateTime()
15 cout<<"\n\nwxDateTime::ParseDateTime():"<<endl;
16
17 //tomorrow 是什么日子?
18 cout<<"tomorrow:"<<endl;
19 wxDateTime tomorrow;
20 tomorrow.ParseDateTime(wxT("tomorrow 11:00am"));
21 cout<<"Tomorrow is "<<tomorrow.Format()<<endl;
22
23 //五一又是什么日子?
24 cout<<"The Labor Day test:"<<endl;
25 wxDateTime laborday;
26 laborday.ParseDate(wxT("May 1st"));
27 cout<<"The Labor Day is "<<laborday.Format()<<endl;
28
29 //至于wxDateSpan,用法非常直白,仅举一例,顺便一提Format的另一种格式:
30 wxDateSpan span(0,1);
31 wxDateTime then=now.Add(span);
32 cout<<then.Format(wxT("%B %d %Y"))<<endl;
33
34 }