Dear Colleagues! Production need asks to write the current time minus 10 minutes and I do not really work. Let me remind you that they get time like this :
#include "stdafx.h" #include <stdio.h> #include <iostream> #include <windows.h> #include <cstddef> // size_t #include <cstring> // strlen, strcpy using namespace std; int main() { setlocale(LC_ALL, "Russian"); SYSTEMTIME st, lt; GetSystemTime(&st); GetLocalTime(<); double dm = st.wMinute - 5; //Π·Π° ΠΌΠΈΠ½ΡΡΠΎΠΌ 5 ΠΌΠΈΠ½ΡΡ double dm1 = lt.wMinute - 5; //Π·Π° ΠΌΠΈΠ½ΡΡΠΎΠΌ 5 ΠΌΠΈΠ½ΡΡ //ΠΡΠΎΡΡΠΎ Π²ΡΠ²ΠΎΠ΄ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ printf("The system time is: %02d:%02d\n", st.wHour, st.wMinute); printf(" The local time is: %02d:%02d\n", lt.wHour, lt.wMinute); //ΠΠΎΠ²ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ Π΄Π»Ρ ΠΌΠΎΠ΅Π³ΠΎ ΠΏΡΠΎΠ΅ΠΊΡΠ°. printf("The system time is: %02d:%02d\n", st.wHour, dm); printf(" The local time is: %02d:%02d\n", lt.wHour, dm1); system("PAUSE"); return 0; } Output:
The system time is: 09:24 The local time is: 12:24 The NEW system time is: 09:00 The NEW local time is: 12:00 It is quite obvious that the third and fourth line cannot satisfy us. How to correctly fix this mess?
printf? Or do you want to say that the value of time changes itself ? - Harrydoublewith the%02d? - Harrydoublewith the%02d. By the link you specify, the integer value is displayed. Start by correcting the output lines. This is not your only problem, you will encounter another when you are thinking of reducing by 5 minutes, say, 2 minutes ... but first, correct the code. Why do you needdoublehere ? - Harry