Raised This Month: $51 Target: $400
 12% 

GetTime offset relative to server's timezone


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 09-19-2020 , 06:10   GetTime offset relative to server's timezone
Reply With Quote #1

This stock allows you to get the amount of seconds the server is before or after unix. I used it to make offsets to use GetTime in a way that works around the end of the day, 00:00. Hopefully it will be useful to you.

Code:
stock int GetTimeOffset()
{
	bool Negate = false;
	char Time[11];

	FormatTime(Time, sizeof(Time), "%A", 86400);
	
	if(StrEqual(Time, "Thursday")) // 86400 in unix is Friday, meaning the timezone brought us back a bit.
		Negate = true;
		
	FormatTime(Time, sizeof(Time), "%H %M", 86400); // Can't use 0 because of negatives I think. I assume.
	
	char sHour[4], sMinute[4];
	
	int pos = BreakString(Time, sHour, sizeof(sHour));
	
	FormatEx(sMinute, sizeof(sMinute), Time[pos]);
	
	int secondstotal = StringToInt(sHour) * 3600 + StringToInt(sMinute) * 60;
	
	if(secondstotal == 0 || !Negate) // Server's time is positive or zero ( unix time )
		return secondstotal;
		
	else 
	{
		/*
		Suppose an hour negative, turns 00:00 into 23:00. The result should be -3600.
		-1 * (86400 - (23 * 3600 + 0 * 60)) = -3600
		*/
		return -1 * (86400 - secondstotal); 
	}
}
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode