MT4/MQL4入门到精通EA教程第八课-MQL语言常用函数(八)-常用时间功能函数

19 篇文章 9 订阅
19 篇文章 14 订阅

时间功能函数详解

TimeCurrent(); //返回服务器当前时间
TimeDayOfWeek();//返回当前时间星期几
TimeGMT();    //返回GTM时间
TimeGMTOffset();  //返回时间差
TimeLocal();    //返回电脑上的时间
TimeHour();     //返回时间中的小时
TimeMinute();   //返回时间中的分
TimeSeconds();  //返回时间中的
TimeDay();  //返回当前时间日期
TimeMonth();   //返回时间中的月
TimeYear();    //返回时间中的年

返回服务器的当前时间(交易商地区的时间)

datetime  TimeCurrent();

返回当前时间的星期几

int  TimeDayOfWeek( 
   datetime      date  
   )
;

返回GTM时间(国际标准时间)

datetime  TimeGMT();

返回国际标准时间与当地时间的时间差

int  TimeGMTOffset();

返回当地时间(电脑上时间)

datetime  TimeLocal();

返回小时

int  TimeHour( 
   datetime      date            // date and time 
   )
;

返回分钟

int  TimeMinute( 
   datetime      date            // date and time 
   )
;

返回秒

int  TimeSeconds( 
   datetime      date            // date and time 
   )
;

返回日期

int  TimeDay( 
   datetime      date            // date and time 
   )
;

返回月份

int  TimeMonth( 
   datetime      date            // date and time 
   )
;

返回年份

int  TimeYear( 
   datetime      date            // date and time 
   )
;

脚本实例:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() 
  {  
    datetime  timecurren    =  TimeCurrent();              //返回交易商服务器当前时间
    datetime  timeGMT       =  TimeGMT();                  //返回GTM时间
    int       timeGMTOffset =  TimeGMTOffset();            //返回时间差
    datetime  timeLocal     =  TimeLocal();                //返回电脑上的时间
    
    int       timeDayOfWeek =  TimeDayOfWeek(timeLocal);   //返回电脑上的时间星期几
    int       timeHour      =  TimeHour(timeLocal);        //返回电脑上的时间的小时
    int       timeMinute    =  TimeMinute(timeLocal);      //返回电脑上的时间的分钟
    int       timeSeconds   =  TimeSeconds(timeLocal);     //返回电脑上的时间的秒
    int       timeDay       =  TimeDay(timeLocal);         //返回电脑上的时间的日期
    int       timeMonth     =  TimeMonth(timeLocal);       //返回电脑上的时间的月份
    int       timeYear      =  TimeYear(timeLocal);        //返回电脑上的时间的年份
  
    Print("timecurren:",timecurren);   
    Print("timeDayOfWeek:",timeDayOfWeek);
    Print("timeGMT:",timeGMT);
    Print("timeGMTOffset:",timeGMTOffset);
    Print("timeLocal:",timeLocal);
    Print("timeHour:",timeHour);
    Print("timeMinute:",timeMinute);
    Print("timeSeconds:",timeSeconds);
    Print("timeDay:",timeDay);
    Print("timeMonth:",timeMonth);
    Print("timeYear:",timeYear);
  
  }

​实例运行结果:
在这里插入图片描述
工欲善其事,必先利其器,交易最重要的是遵守规则,严格执行。关注公众号,学习MQL入门到精通EA教程,学习更多EA编程,畅写属于自己的EA,锻造属于自己的神兵利器。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值