zhongj你进来一下!我给你个函数!
给你几个函数,你愿用那个用那个!
//--------------------------------------------------------------------------
void __fastcall TForm1::SetDateTime ( short int year, short mon, short day, short hour,
short min, short sec )
{
struct date dt;
struct time tm;
dt.da_year = ( int ) year;
dt.da_day = ( char ) day;
dt.da_mon = ( char ) mon;
tm.ti_min = ( BYTE ) min;
tm.ti_hour = ( BYTE ) hour;
tm.ti_sec = ( BYTE ) sec;
tm.ti_hund = 0;
setdate ( & dt ) ;
settime ( & tm ) ;
}
//---------------------------------------------------------------------------------------------
void __fastcall TForm1::SetDateTime ( char *DateTime )
{ //支持yyyymmddhhmmss
char cbuf5[5], cbuf3[3];
short int year, day, mon, hour, min, sec;
memcpy ( cbuf5, DateTime, 4 ) ;
cbuf5[4] = 0;
year = ( short int ) StrToInt ( cbuf5 ) ;
memcpy ( cbuf3, DateTime + 4, 2 ) ;
cbuf3[2] = 0;
mon = ( short int ) StrToInt ( cbuf3 ) ;
memcpy ( cbuf3, DateTime + 6, 2 ) ;
cbuf3[2] = 0;
day = ( short int ) StrToInt ( cbuf3 ) ;
memcpy ( cbuf3, DateTime + 8, 2 ) ;
cbuf3[2] = 0;
hour = ( short int ) StrToInt ( cbuf3 ) ;
memcpy ( cbuf3, DateTime + 10, 2 ) ;
cbuf3[2] = 0;
min = ( short int ) StrToInt ( cbuf3 ) ;
memcpy ( cbuf3, DateTime + 12, 2 ) ;
cbuf3[2] = 0;
sec = ( short int ) StrToInt ( cbuf3 ) ;
SetDateTime ( year, mon, day, hour, min, sec ) ;
}
//---------------------------------------------------------------------
void __fastcall TForm1::SetDateTime ( TDateTime NewDateTime )
{ //支持TDateTime参数
String aa = NewDateTime.FormatString ( "yyyymmddhhmmss") ;
SetDateTime ( aa.c_str () ) ;
}
//---------------------------------------------------------------------------