利用wxTimer动态输出当前系统时间
timer.h
timer.cpp

#include <iostream>


#include
"wx/wxprec.h" 

#ifndef WX_PRECOMP

#include
"wx/wx.h" 
#endif

#include
"timer.h" 
#include <wx/datetime.h>


IMPLEMENT_APP(Netsim)


bool Netsim::OnInit(){

Timer* foo =
new Timer();

wxFrame* frame =
new wxFrame((wxFrame*) NULL, -1, _T(
"Hello wxWidgets World"));

frame->CreateStatusBar();

frame->SetStatusText(_T(
"Hello World"));
//frame->Show(TRUE);
//SetTopWindow(frame);
return true;

}

void Netsim::on_timer( wxTimerEvent& f_event )

{
//获取当前系统时间 
wxString nowTime;

wxDateTime now = wxDateTime::Now();
//中国时区GMT+8,常数为A_WST 
nowTime=now.Format(
"%c", wxDateTime::A_WST).c_str();
//动态在控制台输出当前时间 
std::cout << nowTime << std::endl;

}


Timer::Timer() : wxFrame((wxWindow *)NULL, wxID_ANY, _T("")), m_timer(
this)

{
//时间间隔1秒 
m_timer.Start(1000);

}
转载于:https://blog.51cto.com/axiii/108663