1.
#include <stdio.h>#include <time.h>
void main( void ){/*struct tm {int tm_sec;// seconds after the minute - [0,59]int tm_min;/* minutes after the hour - [0,59]int tm_hour;/* hours since midnight - [0,23]int tm_mday;/* day of the month - [1,31]int tm_mon;/* months since January - [0,11]int tm_year;/* years since 1900int tm_wday;/* days since Sunday - [0,6]int tm_yday;/* days since January 1 - [0,365]int tm_isdst;/* daylight savings time flag}; */ tm systime; _getsystime(&systime); printf( "Current OS date and time: %s", asctime( &systime ) ); tm timetobeset; // below is the value to be set for the system time ( I set it to 2004/12/01 0:00:00 ) : timetobeset.tm_sec=0;// seconds after the minute - [0,59] timetobeset.tm_min=0;// minutes after the hour - [0,59] timetobeset.tm_hour=0;// hours since midnight - [0,23] timetobeset.tm_mday=1;// day of the month - [1,31] timetobeset.tm_mon=11;// months since January - [0,11] timetobeset.tm_year=104;// years since 1900 timetobeset.tm_wday=3;// days since Sunday - [0,6] timetobeset.tm_yday=335;// days since January 1 - [0,365] timetobeset.tm_isdst=0;// daylight savings time flag //_setsystime(&timetobeset, 0); printf( "Current OS date and time is set to be : %s", asctime( &timetobeset ) );}
2.
main(){long i;struct time t1,t2;double dt1,dt2;gettime(&t1);for(i=0;i<500000;i++){ delay(1000);}gettime(&t2);dt1=(double)t1.ti_hour*3600+t1.ti_min*60+t1.ti_sec;dt2=(double)t2.ti_hour*3600+t2.ti_min*60+t2.ti_sec;
printf("\ndifftime:%lf\n",dt2-dt1);getch();} |