最后由 layy 于 2023-1-8 21:21 编辑
如果获取当前系统时间与MT4时间差?如何获取真实GMT值?
直接上代码:
- #import "Kernel32.dll"
- void GetLocalTime(int& a0[]);
- #import
-
- // 获取系统时间
- datetime GetWindowsSystemTime(){
- int TimeArray[4];
- GetLocalTime(TimeArray);
- int year = TimeArray[0] & 65535;
- int month = TimeArray[0] >> 16;
- int day = TimeArray[1] >> 16;
- int hour = TimeArray[2] & 65535;
- int minute = TimeArray[2] >> 16;
- int second = TimeArray[3] & 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);
-
- }
复制代码
|