Reference:
http://blog.sina.com.cn/s/blog_7e2ace6a0100xqk5.html
C++
DWORD GetTickCount();
GetLocalTime(SYSTEMTIME*);
char buffer[1024];
SYSTEMTIME s;
GetLocalTime(&s);
sprintf(buffer, "%d-%d-%d %d:%d:%d", s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond);
cout<<"Now:"<<buffer<<endl;
C#
TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); //获取当前时间的刻度数
//你的代码或者其他操作
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts = ts2.Subtract(ts1).Duration();//时间差的绝对值,测试你的代码运行了多长时间。
String spanTime = ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分" + ts.Seconds.ToString() + "秒";
//以X小时X分X秒的格式显示执行时间