#include "stdafx.h"
#include <sys/timeb.h>
#include <time.h>
#include <iostream>
using namespace std;
class TIME
{
private:
double timeM;
int time_H;
int time_M;
int time_S;
double millisecond;
public:
void cal();
double getSystime();
int getH();
int getM();
int getS();
};
void TIME::cal()
{
struct _timeb timebuffer;
char *timeline;
unsigned short millitml;
char temp_H[2];
char temp_M[2];
char temp_S[2];
_ftime(&timebuffer);
timeline=ctime(&(timebuffer.time));
millitml=timebuffer.millitm;
millisecond=(double)millitml/1000;
for(int i=0;i<2;i++)
{
temp_H[i]=timeline[i+11];
}
for(int j=0;j<2;j++)
{
temp_M[j]=timeline[j+14];
}
for(int k=0;k<2;k++)
{
temp_S[k]=timeline[k+17];
}
time_H=atoi(temp_H);
time_M=atoi(temp_M);
time_S=atoi(temp_S);
timeM=double(time_H)*3600+double(time_M)*60+double(time_S)+millisecond;
}
double TIME::getSystime()
{
return timeM;
}
int TIME::getH()
{
return time_H;
}
int TIME::getM()
{
return time_M;
}
int TIME::getS()
{
return time_S;
}
void main()
{
TIME t;
t.cal();
cout<<"当前系统时间值:"<<t.getSystime()<<"毫秒"<<endl;
cout<<"时:"<<t.getH()<<endl;
cout<<"分:"<<t.getM()<<endl;
cout<<"秒:"<<t.getS()<<endl;
getchar();
}