time, data [clock]
#1

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);

Reply
#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
#3

added to the hour + 4 ,time on the server 24.30 instead of 00 30 (((((((((((
Reply
#4

Quote:
Originally Posted by EvgeniyHostel1992
Посмотреть сообщение
added to the hour + 4 ,time on the server 24.30 instead of 00 30 (((((((((((
Yes you must wrap it around if it gets higher than 23, like this:

Код:
hour += 4;

if(hour >= 24) hour -= 24;
Problem is though, it will show a wrong date when doing this.


For a correct GMT interpolation you would also need to adjust the date to the current timezone, but you can save yourself that work if you use an Include, like this one:

https://sampforum.blast.hk/showthread.php?tid=347605

You should then replace gettime() and getdate() with this code:

Код:
TimestampToDate(gettime(), year, month, day, hours, minutes, seconds, 4);
This will get time and date for GMT + 4, so you don't need to add 4 to hour yourself.
Reply
#5

thx, friend! Hello from Ukraine)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)