StringToTime

"yyyy.mm.dd [hh:mi]" 서식의 시간 및 날짜를 포함하는 문자열을 datetime 유형 번호로 변환.

datetime  StringToTime(
   const string  time_string      // 날짜 문자열
   );

매개변수

time_string

[in]  지정된 서식 중 하나의 문자열:

  •  "yyyy.mm.dd [hh:mi]"
  •  "yyyy.mm.dd [hh:mi:ss]"
  •  "yyyymmdd [hh:mi:ss]"
  •  "yyyymmdd [hhmiss]"
  •  "yyyy/mm/dd [hh:mi:ss]"
  •  "yyyy-mm-dd [hh:mi:ss]"

값 반환

datetime 유형 값으로 1970.01.01 이후 경과된 시간(초)을 포함합니다.

주의

날짜와 시간 사이의 공백 및 테이블 문자 시퀀스는 time_string이 추가 처리되지 않도록 StringToTime() 호출하기 전에 단일 공백으로 간주됩니다.

 

예:

//--- 입력 매개변수
input group    "The date can be entered in any of the formats:"
input group    "yyyy.mm.dd [hh:mi], yyyy.mm.dd [hh:mi:ss]"
input group    "yyyymmdd [hh:mi:ss], yyyymmdd [hhmiss]"
input group    "yyyy/mm/dd [hh:mi:ss], yyyy-mm-dd [hh:mi:ss]"
input string   InpDateStr;    // Please enter the date here as a string
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 입력에 문자열로 입력된 시간을 날짜/시간 값으로 변환합니다.
   datetime time=StringToTime(InpDateStr);
//--- 입력한 문자열과 얻은 시간을 저널에 표시합니다.
   PrintFormat("Date entered as a string in the form '%s' is converted to datetime in the form '%s'",
               InpDateStrTimeToString(timeTIME_DATE|TIME_MINUTES|TIME_SECONDS));
//--- 수신된 날짜-시간에 수직선을 생성하고 차트를 이 위치로 이동합니다.
   if(CreateVLine(time))
      ChartNavigateToTime(time);
   /*
   result:
   Date entered as a string in the form '' is converted to datetime in the form '1970.01.01 00:00:00'
   Date entered as a string in the form '2024is converted to datetime in the form '2024.02.24 20:24:00'
   Date entered as a string in the form '202400is converted to datetime in the form '2024.02.24 20:24:00'
   Date entered as a string in the form '20240000is converted to datetime in the form '2024.02.24 00:00:00'
   Date entered as a string in the form '2024022410is converted to datetime in the form '2030.09.06 00:00:00'
   Date entered as a string in the form '20240224 10is converted to datetime in the form '2024.02.24 10:00:00'
   Date entered as a string in the form '20240224 01is converted to datetime in the form '2024.02.24 01:00:00'
   Date entered as a string in the form '20240224 0030is converted to datetime in the form '2024.02.24 23:00:00'
   Date entered as a string in the form '20240224 0100is converted to datetime in the form '2024.02.24 01:00:00'
   */
  }
//+------------------------------------------------------------------+
//| 수직선 객체 만들기                                                 |
//+------------------------------------------------------------------+
bool CreateVLine(const datetime line_time)
  {
   ResetLastError();
 
   string name=MQLInfoString(MQL_PROGRAM_NAME)+"_VLINE";
   if(!ObjectCreate(0nameOBJ_VLINE0line_time0))
     {
      Print("ObjectCreate() failed. Error code: "GetLastError());
      return(false);
     }
   ObjectSetInteger(0nameOBJPROP_STYLESTYLE_DOT);
   ObjectSetInteger(0nameOBJPROP_SELECTABLEtrue);
 
   return(true);
  }
//+------------------------------------------------------------------+
//| 차트를 지정된 바 오픈 시간으로 이동                                  |
//+------------------------------------------------------------------+
bool ChartNavigateToTime(const datetime time)
  {
   ChartSetInteger(0CHART_AUTOSCROLLfalse);
   ResetLastError();
 
   int bar=iBarShift(_SymbolPERIOD_CURRENTtime);
   if(bar<0)
     {
      PrintFormat("%s: iBarShift() failed. Error code: %d"__FUNCTION__GetLastError());
      return(false);
     }
 
   long first=0;
   if(!ChartGetInteger(0CHART_FIRST_VISIBLE_BAR0first))
     {
      PrintFormat("%s: ChartGetInteger() failed. Error code: %d"__FUNCTION__GetLastError());
      return(false);
     }
 
   return(ChartNavigate(0CHART_CURRENT_POS, (int)first-bar));
  }

추가 참조

TimeToString, TimeToStruct