法一:调用C函数库
#include <iostream.h>
#include <time.h>
void main( void )
{
struct tm *newtime; //tm结构体为时间库中定义,成员变量包括时,分,秒,年等。
time_t long_time;
time( &long_time ); //获取系统时间
newtime = localtime( &long_time ); //Converts a time value and corrects for the local time zone.
int h = newtime->tm_hour;//得到当前时间的小时
int m = newtime->tm_min;//得到当前时间的分钟
cout<<h<<" "<<m<<endl;
}