Учимся прибавлять, отнимать часы или минуты во времени из локальных часов на компьютере на С++
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#include <DateUtils.hpp> //Подключаем хедер для работы с датой и временем
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label1->Caption="Local time: "+Time().FormatString("hh:mm:ss"); //Локальное время компьютера
Label2->Caption="Moscow -5 Hours: "+IncHour(Time(),-5); //Разница с Москвой минус 5 часов
Label3->Caption="Vladivostok +2 Hours: "+IncHour(Time(),+2); //Разница с Владивостоком плюс 2 часа
Label4->Caption="Local time +10 Minutes: " +IncMinute(Time(), +10); //К локальному времени компьютера прибавить 10 минут
}
//---------------------------------------------------------------------------
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TTimer *Timer1;
void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif