Question about how....

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Post Reply
Pschilly
Registered User
Posts: 28
Joined: Wed Sep 24, 2003 7:10 pm
Contact:

Question about how....

Post by Pschilly »

I was wondering... how does the date function on this forum work with the user inputted timezones?? I cannot seem to find it in the source... would someone be able to tell me what file to look in? Or even better just tell me how it works! lol


Thanks in advanced...


~Pat

User avatar
haravikk
Registered User
Posts: 292
Joined: Sun Apr 20, 2003 5:05 pm
Contact:

Re: Question about how....

Post by haravikk »

Without looking at the code I'd imagine that the value you choose for hours ahead (positive) of GMT and behind (negative) can be used in a simple math equation.

Since the time format is the unix one measured in seconds since the unix epoch (1st January 1970 iirc) then the current time can be adjust by adding the time difference in seconds.

For example, say you are 6 hours ahead of GMT which the current time is measured in, then the time is just the current time + 6 * 3600 where the 3600 is an hour in seconds, this would work for negative values too since current time + -6 * 3600 would work out the time 6 hours ago.

I'll have a quick look a bit later if no one else has confirmed/corrected this
Images in sigs! please.

Pschilly
Registered User
Posts: 28
Joined: Wed Sep 24, 2003 7:10 pm
Contact:

Re: Question about how....

Post by Pschilly »

Yea, i figured it out about 20 minutes after posting that hehehe...

Heres what i did:

Code: Select all

<?php 
Where the \ n's are, remove the space from between them.
echo gmdate('M d Y g:i', gmdate('U') + (-5 * 3600)) , "\ n"; 

?>
To make it "user inputable" you would need to do something like:

Code: Select all

<?php 

// &tz being a var, that is the timezone from -13 to +13

echo gmdate('M d Y g:i', gmdate('U') + (&tz * 3600)) , "\ n";


?>

DoD
Registered User
Posts: 360
Joined: Sat Aug 30, 2003 11:32 am

Re: Question about how....

Post by DoD »

Hehe.

This is the function i use:

Code: Select all

function generate_date($dateformat, $timestamp, $tz)
{
	if( date('I', $timestamp) )
	{
		$tz = $tz + 1;
	}
return gmdate ($dateformat, ($timestamp + ($tz * 3600)));
}
its pretty simple. But this one also take into account day light savings...

Post Reply