#property script_show_inputs
input int InpYear = 0; 연도
input int InpMonth = 0; // 월
input int InpDay = 0; // 일
input int InpHour = 0; // 시
input int InpMin = 0; // 분
input int InpSec = 0; // 초
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 입력된 값을 조정하고 변수에 씁니다.
int year = (InpYear<1970 ? 1970 : InpYear); // 입력한 연도가 1970년보다 작으면 1970년이 사용됩니다.
int month= (InpMonth<1 ? 1 : InpMonth > 12 ? 12 : InpMonth);
int day = (InpDay <1 ? 1 : InpDay > 31 ? 31 : InpDay);
int hour = (InpHour <0 ? 0 : InpHour > 23 ? 23 : InpHour);
int min = (InpMin <0 ? 0 : InpMin > 59 ? 59 : InpMin);
int sec = (InpSec <0 ? 0 : InpSec > 59 ? 59 : InpSec);
//--- 입력된 값을 로그에 표시합니다.
PrintFormat("Entered date and time: %04u.%02u.%02u %02u:%02u:%02u", InpYear, InpMonth, InpDay, InpHour, InpMin, InpSec);
//--- 조정된 입력 값을 로그에 표시합니다.
PrintFormat("Corrected date and time: %04u.%02u.%02u %02u:%02u:%02u", year, month, day, hour, min, sec);
//--- 해당 구조 필드에 입력 값을 씁니다.
MqlDateTime time_struct={};
time_struct.year= year;
time_struct.mon = month;
time_struct.day = day;
time_struct.hour= hour;
time_struct.min = min;
time_struct.sec = sec;
//--- 구조체의 날짜와 시간을 datetime 유형의 변수로 변환하고
datetime time = StructToTime(time_struct);
//--- MqlDateTime 구조체 유형 변수를 datetime 유형 값으로 변환한 결과를 표시합니다.
Print("Converted date and time: ",TimeToString(time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
/*
기본값이 0으로 입력되면 결과는 다음과 같습니다.
Entered date and time: 0000.00.00 00:00:00
Corrected date and time: 1970.01.01 00:00:00
Converted date and time: 1970.01.01 00:00:00
올해 2월의 날짜를 잘못 입력한 경우 결과:
Entered date and time: 2024.02.31 00:00:00
Corrected date and time: 2024.02.31 00:00:00
Converted date and time: 2024.03.02 00:00:00
*/
}
|