#include <e32base.h>
#include <e32cons.h>
_LIT(KTxtExampleCode,"时间演示");
LOCAL_D CConsoleBase* console;
//执行例子程序
LOCAL_C void callExampleL();
LOCAL_D TInt error;
LOCAL_C void Exit();
//主函数
GLDEF_C TInt E32Main()
{
__UHEAP_MARK;
CTrapCleanup* cleanup=CTrapCleanup::New();
TRAP(error,callExampleL());
__ASSERT_ALWAYS(!error,User::Panic(_L("Error Exit"),error));
delete cleanup;
__UHEAP_MARKEND;
return 0;
}
LOCAL_C void callExampleL()
{
console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
CleanupStack::PushL(console);
//TTime* myTime=new TTime();
console->Printf(_L("PressKey...\n"));
TInt i=0;
TInt key=-1;
do
{
key=console->Getch();
console->Printf(_L("[%C]\n"),key);
if(key==99)
{
console->ClearScreen();
}
//TDateTime 示例代码
if(key==49)
{
console->SetTitle(_L("TDateTime Demo"));
// TDateTime 可以有两个构造函数,带参数和不带参数;
TDateTime dtm_1;
TDateTime* dtm_2=new TDateTime(1996,ENovember,5,00,00,00,000000);
TDateTime* dtm_3=new TDateTime();
//定义以后,可以对日期进行设置
dtm_1.Set(2005,EOctober,8,23,40,43,145654);
//也可以单独设置,如:
dtm_2->SetYear(2004);
//输出时间
console->Printf(_L("%d年"),dtm_1.Year());
console->Printf(_L("%d月"),dtm_1.Month());
console->Printf(_L("%d日\n"),dtm_1.Day());
console->Printf(_L("%d:"),dtm_1.Hour());
console->Printf(_L("%d:"),dtm_1.Minute());
console->Printf(_L("%d\n"),dtm_1.Second());
//dtm_3 没有初始化
console->Printf(_L("%d年"),dtm_3->Year());
console->Printf(_L("%d月"),dtm_3->Month());
console->Printf(_L("%d日\n"),dtm_3->Day());
console->Printf(_L("%d:"),dtm_3->Hour());
console->Printf(_L("%d:"),dtm_3->Minute());
console->Printf(_L("%d\n"),dtm_3->Second());
}
// TTime 示例代码
if(key==50)
{
console->SetTitle(_L("TTime Demo"));
TTime ttm_1;
TTime* ttm_2=new TTime(_L("20050309:125825."));
_LIT(MyTmStr,"20640102:");
ttm_1.Set(MyTmStr);
// 获取当前系统时间
ttm_2->HomeTime();
//ttm_2+=2;
TDateTime tdm=ttm_2->DateTime();
//输出时间
console->Printf(_L("%d年"),tdm.Year());
console->Printf(_L("%d月"),(1+tdm.Month()));
console->Printf(_L("%d日\n"),(1+tdm.Day()));
console->Printf(_L("%d:"),tdm.Hour());
console->Printf(_L("%d:"),tdm.Minute());
console->Printf(_L("%d\n"),tdm.Second());
}
if(key==27)
{
console->Write(_L("EndProgram...\n"));
User::Panic(_L("Normal Exit"),3302);
}
i++;
}while(i<1000);
CleanupStack::PopAndDestroy();
}
//结束程序
LOCAL_C void Exit()
{
}