layy 发表于 2023-1-8 21:20:39

如果获取当前系统时间与MT4时间差?如何获取真实GMT值?

最后由 layy 于 2023-1-8 21:21 编辑

如果获取当前系统时间与MT4时间差?如何获取真实GMT值?
直接上代码:
#import "Kernel32.dll"
   void GetLocalTime(int& a0[]);
#import

// 获取系统时间
datetime GetWindowsSystemTime(){
int TimeArray;
   GetLocalTime(TimeArray);
   int year = TimeArray & 65535;
   int month = TimeArray >> 16;
   int day = TimeArray >> 16;
   int hour = TimeArray & 65535;
   int minute = TimeArray >> 16;
   int second = TimeArray & 65535;
   
   return StringToTime( FormatDateTime(year, month, day, hour, minute, second) );
}

// 获取GMT值
int GMTOffset() {
   double dbDiff = TimeCurrent() - GetWindowsSystemTime();
   return (MathRound(dbDiff / 3600.0));
}

// 格式化时间
string FormatDateTime(int year, int iMonth, int iDay, int iHour, int iMinute, int iSecond) {
   string month = IntegerToString(iMonth + 100);
   month = StringSubstr(month, 1);
   string day = IntegerToString(iDay + 100);
   day = StringSubstr(day, 1);
   string hour = IntegerToString(iHour + 100);
   hour = StringSubstr(hour, 1);
   string minute = IntegerToString(iMinute + 100);
   minute = StringSubstr(minute, 1);
   string second = IntegerToString(iSecond + 100);
   second = StringSubstr(second, 1);
   return StringFormat("%d.%s.%s %s:%s:%s", year, month, day, hour, minute, second);

}



ken138888 发表于 2023-1-10 19:47:24

这是mt4还是mt5

ea12213 发表于 2023-1-11 20:08:17

挺有用的

ainibaige 发表于 2023-2-17 10:50:47

这是指标还是ea呢?

ainibaige 发表于 2023-2-17 10:54:39

放在指标和ea文件里都不行

lyldr 发表于 2023-2-21 15:00:32

获取真实GMT值

dongxu64 发表于 2023-2-27 08:32:29

实用,谢谢楼主。

yuiran 发表于 2023-2-27 11:13:25

这个怎么使用?

ken138888 发表于 2023-3-16 20:43:26

有什么用呢?

qwe11 发表于 2023-3-16 21:30:44

怎么用??

k2222hk 发表于 2023-4-20 15:31:13

感谢分享。好东西

daerwushen 发表于 2023-4-23 08:35:00

挺实用啊

daerwushenn 发表于 2023-4-23 08:39:49

格林威治标准时间

joker888 发表于 2023-4-23 14:42:54

有什么用呢?~~

daodao123 发表于 2023-5-11 11:51:43

这个不错,点赞

tststs 发表于 2023-5-22 20:09:51

不错,学习了

xcf2004 发表于 2023-11-16 07:38:08

嗯,有时会用到这个方法

shllwk 发表于 2023-11-16 08:30:26

不错,学习了不错,学习了

yangxiao 发表于 2025-6-18 18:04:20

这个实用,感谢分享。

yadang120 发表于 2025-7-7 11:43:26

这个代码好复杂, 看看还是可以的。
页: [1] 2
查看完整版本: 如果获取当前系统时间与MT4时间差?如何获取真实GMT值?