TimeLocal

Returns the local time of a computer, where the client terminal is running. There are 2 variants of the function.

Call without parameters

datetime  TimeLocal();

Call with MqlDateTime type parameter

datetime  TimeLocal(
   MqlDateTime&  dt_struct      // Variable of structure type
   );

Parameters

dt_struct

[out]  Variable of structure type MqlDateTime.

Return Value

Value of datetime type

Note

If the MqlDateTime structure type variable has been passed as a parameter, it is filled accordingly.

To arrange high-resolution counters and timers, use the GetTickCount() function, which produces values in milliseconds.

During testing in the strategy tester, TimeLocal() is always equal to TimeCurrent() simulated server time.

Example:

void OnStart()
  {
//--- declare the MqlDateTime variable to be filled with PC local time data
   MqlDateTime tm={};
   datetime    time1=TimeLocal();   // first form of call: PC local time
   datetime    time2=TimeLocal(tm); // second form of call: PC local time with filling the MqlDateTime structure
   
//--- display the result of receiving PC local time and filling the structure with the corresponding data in the log
   PrintFormat("Local time: %s\n- Year: %u\n- Month: %02u\n- Day: %02u\n- Hour: %02u\n- Min: %02u\n- Sec: %02u\n- Day of Year: %03u\n- Day of Week: %u (%s)",
               (string)time1tm.yeartm.montm.daytm.hourtm.mintm.sectm.day_of_yeartm.day_of_weekEnumToString((ENUM_DAY_OF_WEEK)tm.day_of_week));
   /*
   result:
   Local time2024.04.18 19:44:09
   - Year2024
   - Month04
   - Day18
   - Hour19
   - Min44
   - Sec09
   - Day of Year108
   - Day of Week4 (THURSDAY)
   */
  }