Help with textdraw watch
#1

Hello I have textdraw watch, it works perfect, but my host is in another country and there time is different. I want to add +1 hour +3 minutes and +15 seconds to equalize the time, but when I added, there were many bugs (9:52:72 (hours, minutes, seconds)). And I think there will be more bugs at the date. Here is my system:
Quote:

new string[256],year,month,day,hours,minutes,seconds;
getdate(year, month, day), gettime(hours, minutes, seconds);
format(string, sizeof string, "%d/%s%d/%s%d", day, ((month < 10) ? ("0") : ("")), month, (year < 10) ? ("0") : (""), year);
TextDrawSetString(Date, string);
format(string, sizeof string, "%s%d:%s%d:%s%d", (hours < 10) ? ("0") : (""), hours, (minutes < 10) ? ("0") : (""), minutes, (seconds < 10) ? ("0") : (""), seconds);
TextDrawSetString(Time, string);

Will you be able to add 1 hour, 3 minutes and 15 seconds to that time?
Reply
#2

Okay, first of all don't use this noobish method of adding leading zeros, use %02d instead.

PHP Code:
format(stringsizeof(string), "%02d:%02d:%02d"hoursminutesseconds); 
If "your host" is off standard time by more than 3 minutes then you should ask "your host" to use an NTP server. The best solution would simply be to change the time on the server but if you can't do that then you can add however many hours you want and perform a mod 24. It would then become:

PHP Code:
format(stringsizeof(string), "%02d:%02d:%02d", (hours 1) % 24minutesseconds); 
So if hour was 23 and you added 1 then the hour would become (23 + 1) % 24 = 0.
Reply
#3

Quote:
Originally Posted by Vince
View Post
Okay, first of all don't use this noobish method of adding leading zeros, use %02d instead.

PHP Code:
format(stringsizeof(string), "%02d:%02d:%02d"hoursminutesseconds); 
If "your host" is off standard time by more than 3 minutes then you should ask "your host" to use an NTP server. The best solution would simply be to change the time on the server but if you can't do that then you can add however many hours you want and perform a mod 24. It would then become:

PHP Code:
format(stringsizeof(string), "%02d:%02d:%02d", (hours 1) % 24minutesseconds); 
So if hour was 23 and you added 1 then the hour would become (23 + 1) % 24 = 0.
Okay, you added just +1 hour, but can you add 3 minutes and 15 seconds too and will there be a problem in the date?
Reply
#4

Help?
Reply
#5

Quote:
Originally Posted by Kraeror
View Post
but can you add 3 minutes and 15 seconds too
Hypothetically you could but it doesn't make sense because timezones don't work that way. If in your timezone it's 17:35 then on the server it ought to be 16:35. A discrepancy of more than a few seconds is a sign that the server hasn't synced with a network time server in a long time.
Reply
#6

Quote:
Originally Posted by Vince
View Post
Hypothetically you could but it doesn't make sense because timezones don't work that way. If in your timezone it's 17:35 then on the server it ought to be 16:35. A discrepancy of more than a few seconds is a sign that the server hasn't synced with a network time server in a long time.
Okay f*ck this minutes and seconds, but if I add your method with +1 hour, will be any problem?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)