C++ BUILDER XE IdDayTime точное время
=
=
=
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( ComboBox1->Text != "" && ListBox1->ItemIndex != -1){
if( IdDayTime1->Connected() ) IdDayTime1->Disconnect();
UnicodeString s, d, zn, sh ;
zn = ListBox1->Items->Strings[ListBox1->ItemIndex ].SubString(1,1) ;
sh = ListBox1->Items->Strings[ListBox1->ItemIndex ].SubString(2,2) ;
TDateTime dt,pt;
TSystemTime st;
Edit1->Text = ""; Edit2->Text = "";
TFormatSettings FormatSettings;
FormatSettings.DateSeparator = '.';
FormatSettings.TimeSeparator = ':';
FormatSettings.LongDateFormat = "DD.MM.YY";
FormatSettings.ShortDateFormat = "DD.MM.YY";
FormatSettings.ShortTimeFormat = "HH:MM:SS";
FormatSettings.LongTimeFormat = "HH:MM:SS";
try {
IdDayTime1->Host = ComboBox1->Text ; //
IdDayTime1->Port = 13;
s = IdDayTime1->DayTimeStr ;
IdDayTime1->Disconnect();
}
catch (...) {
IdDayTime1->Disconnect(); Edit1->Text = "Сервер не отвечает"; return;
}
if(s == ""){ Edit1->Text = "Сервер не отвечает"; return; }
else {
Edit1->Text = s;
d= s.SubString(13,2) + "." +
s.SubString(10,2)+ "." +
s.SubString(7,2) + " " +
s.SubString(16,2) + ":" +
s.SubString(19,2) + ":" +
s.SubString(22,2) ;
dt = StrToDateTime( d);
if(zn == "+" || zn == "0"){
pt = StrToDateTime( sh + ":00" + ":00" );
dt = dt + pt;
}
if(zn == "-" ){
pt = StrToDateTime(sh+":00"+":00" );
dt=dt-pt;
}
Edit2->Text = DateTimeToStr(dt) ;
if( RadioButton1->Checked ){
DateTimeToSystemTime(dt,st);
SetLocalTime( &st );
}
}
} else ShowMessage("Заполни поле хост или выбери пояс");
}
//---------------------------------------------------------------------------
=
|