TimeToStruct

Produit la conversion de la valeur du type datetime (le nombre de secondes depuis le 01.01.1970) à la variable du type de la structure MqlDateTime.

bool  TimeToStruct(
   datetime      dt,            // date et temps
   MqlDateTime&  dt_struct      // structure pour l'adoption de valeurs
   );

Paramètres

dt

[in]  La valeur de la date pour la conversion.

dt_struct

[out]  La variable du type de la structure MqlDateTime.

La valeur rendue

true — en cas du succès, autrement false. Pour recevoir l'information sur l'erreur, il faut appeler la fonction GetLastError().

Example:

void OnStart()
  {
//--- get the last known time of the server, declare the date/time structure and fill in the structure fields
   datetime    time=TimeCurrent();
   MqlDateTime tm  ={};
   if(!TimeToStruct(time,tm))
      Print("TimeToStruct() failed. Error "GetLastError());
   
//--- display the obtained server time and the result of filling the MqlDateTime structure using TimeToStruct() in the log
   PrintFormat("Server 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)timetm.yeartm.montm.daytm.hourtm.mintm.sectm.day_of_yeartm.day_of_weekEnumToString((ENUM_DAY_OF_WEEK)tm.day_of_week));
   /*
   result:
   Server time2024.04.18 15:47:27
   - Year2024
   - Month04
   - Day18
   - Hour15
   - Min47
   - Sec27
   - Day of Year108
   - Day of Week4 (THURSDAY)
   */
  }