how to get time, when
#1

Hi,

I store my server in host. But problem is hosting time is +2 more, then time in my countrie. If now is 11:00, then if i get time, it will wrote 1:00. How to get time, but that time, what is in real time, what is in my computer, just real time.
Reply
#2

Times are not the same for every player (who lives in different country that yours).

Well, if you want to show the time of your country.

pawn Код:
new
    hour,
    minute,
    second
;
gettime( hour, minute, second );
printf( "%02d:%02d", hour - 2, minute );
// Using hour - 2 will show your time, then show it by chat, textdraws or whatever you want!
Reply
#3

The above poster is correct, but keep in mind that time goes from 0 to 23. A correct function would be:

pawn Код:
stock GetRealTime(&hours, &minutes, &seconds, timezone_offset = 0) {
    gettime(hours, minutes, seconds);

    hours += timezone_offset;
    hours = hours < 0 ? (hours + 24) : hours;
    hours = hours > 23 ? (hours - 24) : hours;
}

// Can be used as
new hours, minutes, seconds;
new timezone_offset = -2; // Server timezone is 2 hours ahead of the timezone you want

GetRealTime(hours, minutes, seconds, timezone_offset);

printf("%02d:%02d:%02d", hours, minutes, seconds); // prints real time
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)