I got now GPS working (GPSmap 76 from Garmin) on the Arduino.
So the GPS does give me the Time in UTC. I need now to add or
subtract the a number to fit to my Time Zone.
I do print all information with an array to the serial port.
How do I combine a array of to numbers to an int or something
similar so that I can add a number to correct the time zone?
stunde[j] = linea[j+1]; //Read the first Number of the the Time (21:15 => stunde[j]=2)
if (st == 0){ //So for the first number
stu = stunde[j];
if (stu == 49){ //49=1 so if yes then multipli by ten or just put the stu=10
stu = 10;
}
if (stu == 50){ //50=2 so if yes then multipli by ten or just put the stu=20
stu = 20;
}
if (stu == 48){
stu = 0;
}
}
else{ //So for the second number
stun = stunde[j];
stu = stu + (stun - 48) + zone; //here is the time zone, mine is +2 so the calculation is for 21:15: 19 + (49-48) + 2
if (stu >= 24){ // if its more the 24 like 25 or 26 put it to 00 or 01
stu = stu - 24;
}
Serial.print(stu);
lcd.printIn("Zeit: "); //Zeit menas time in german :)
lcd.printIn(itoa(stu, buf, 10));
}
Here is a code fragment that may get you in the right direction
char timeStr[6] = {"12:30"}; // timeStr is our time string, for demo purposes we initialise it to some time
int tzOffset = 1; // lets say the offset is 1
int hour = ((timeStr[0] - '0') * 10) + timeStr[1] - '0'; // calculate the hour as in integer, in this code we assume the first char will be zero if the time is less than 10 oclock
int localHour = (hr + tzOffset) % 24; // % is the modulus operator, this is the same as the following:
//if(localHr >= 24) //
// localHr = LocalHr - 24;
char c = (localHr / 10) + '0'; // calculate the tens of hours character
timeStr[0] = c; // and put it into our time string
c = localHr[1] + '0'; // calculate the hours char
timeStr[1] = c; // and put that in the string
//timeStr should now be the local time string
Here is a code fragment that may get you in the right direction
char timeStr[6] = {"12:30"}; // timeStr is our time string, for demo purposes we initialise it to some time
int tzOffset = 1; // lets say the offset is 1
int hour = ((timeStr[0] - '0') * 10) + timeStr[1] - '0'; // calculate the hour as in integer, in this code we assume the first char will be zero if the time is less than 10 oclock
int localHour = (hr + tzOffset) % 24; // % is the modulus operator, this is the same as the following:
//if(localHr >= 24) //
// localHr = LocalHr - 24;
char c = (localHr / 10) + '0'; // calculate the tens of hours character
timeStr[0] = c; // and put it into our time string
c = localHr[1] + '0'; // calculate the hours char
timeStr[1] = c; // and put that in the string
//timeStr should now be the local time string
ah great with 3 lines of code it does work much smoother
int hr = ((timeStr[0]) - '0') * 10 + timeStr[1] - '0';
int st = ((timeStr[3] -'0') *10 + timeStr[4] - '0');
int localHr = (hr + tzOffset) % 24;