参数部分代码:
- extern int StartHour=21 ;//开始交易(小时)
- extern int StartMinute=0 ; //开始交易(分钟)
- extern int StopHour=3 ;//停止交易(小时)
- extern int StopMinute=0 ;//停止交易(分钟)
复制代码
主函数的控制代码:
- if(!TimeLimit(TimeCurrent(),StartHour,StartMinute,StopHour,StopMinute)) return;
复制代码
用到的函数代码:
- bool TimeLimit (datetime TimeX,int StartHourX,int StartMinuteX,int StopHourX,int StopMinuteX)
- {
- string CurrentTime;
- string StartTime;
- string StopTime;
- bool Var=FALSE;
- //----------------------------
-
- CurrentTime = TimeToString(TimeX,TIME_MINUTES) ;
- StartTime = StringFormat("%02d",StartHourX) + ":" + StringFormat("%02d",StartMinuteX) ;
- StopTime = StringFormat("%02d",StopHourX) + ":" + StringFormat("%02d",StopMinuteX) ;
- if(StringCompare(CurrentTime,StartTime,true)>=0 && StringCompare(CurrentTime,StopTime,true)<=0
- ||(StringCompare(StartTime,StopTime,true)>0 && ( StringCompare(CurrentTime,StartTime,true)>=0 && StringCompare(CurrentTime,"23:59",true)<=0
- || ( StringCompare(CurrentTime,"00:00",true)>=0 && StringCompare(CurrentTime,StopTime,true)<=0))))
- Var=TRUE;
- return(Var);
- }
复制代码
|