time, data [clock]
#2

Quote:
Originally Posted by EvgeniyHostel1992
Посмотреть сообщение
Here is the script. Updating time and date - every second. Tell me, is there a load on the server due to this timer? And is there an easier solution for setting the clock / date on the server?
And another question, tell me how to change the time zone on the server? SetWorldTime does not help ...
PHP код:
SetTimer("time"1000true);
forward time();
public 
time()
{
        new 
string[256], yearmonthdayhoursminutesseconds;
        
getdate(yearmonthday), gettime(hoursminutesseconds);
        
format(stringsizeof string"%d/%s%d/%s%d"day, ((month 10) ? ("0") : ("")), month, (year 10) ? ("0") : (""), year);
        
TextDrawSetString(Datestring);
        
format(stringsizeof string"%s%d:%s%d:%s%d", (hours 10) ? ("0") : (""), hours, (minutes 10) ? ("0") : (""), minutes, (seconds 10) ? ("0") : (""), seconds);
        
TextDrawSetString(Timestring);

This timer does almost nothing compared to actually CPU intensive code, so don't worry about that.

You could however strip Date and Time since the Date only changes once a day, but that doesn't really make a difference.

One suggestion though, you can use format specifiers to show "2" as "02" by doing

Код:
format(string, sizeof string, "%02d:%02d:%02d", hours, minutes, seconds);
And the same for the date. That will add leading zeros without having to use any extra code for that.

Furthermore the string size can be much lower. Neither of the strings is going to reach even 10 characters.

To simulate a different timezone you can add/subtract X from the hour variable, and check if the new hour wrapped to another day (eg. hour 25 would be 1:00:00 and the next day, hour -1 would be hour 23 of the previous day).
Reply


Messages In This Thread
time, data [clock] - by EvgeniyHostel1992 - 02.03.2018, 15:18
Re: time, data [clock] - by NaS - 02.03.2018, 15:33
Re: time, data [clock] - by EvgeniyHostel1992 - 02.03.2018, 18:29
Re: time, data [clock] - by NaS - 02.03.2018, 19:10
Re: time, data [clock] - by EvgeniyHostel1992 - 02.03.2018, 19:20

Forum Jump:


Users browsing this thread: 1 Guest(s)