void OnStart()
{
//--- 声明MqlDateTime变量以填充日期/时间数据,并获取最后报价的时间和估算的交易服务器当前时间
MqlDateTime tm={};
datetime time_current=TimeCurrent(); // 第一种调用形式:市场报价窗口中某一交易品种的最后报价时间
datetime time_server =TimeTradeServer(tm); // 第二种调用形式:通过填充MqlDateTime结构估算交易服务器的当前时间
int difference =int(time_current-time_server); // 当前时间和交易服务器时间的差异
//--- 使用日志中填充的MqlDateTime结构的数据显示最后报价的时间和估算的交易服务器当前时间
PrintFormat("Time Current: %s\nTime Trade Server: %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)\nDifference between Time Current and Time Trade Server: %+d",
(string)time_current, (string)time_server, tm.year, tm.mon, tm.day, tm.hour, tm.min, tm.sec, tm.day_of_year, tm.day_of_week,
EnumToString((ENUM_DAY_OF_WEEK)tm.day_of_week), difference);
/*
Result:
Time Current: 2024.04.18 16:10:14
Time Trade Server: 2024.04.18 16:10:15
- Year: 2024
- Month: 04
- Day: 18
- Hour: 16
- Min: 10
- Sec: 15
- Day of Year: 108
- Day of Week: 4 (THURSDAY)
Difference between Time Current and Time Trade Server: -1
*/
}
|