WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Local-to-user date and time display regardless of time zone or where the website's server is located
Categories : PHP, Date Time, HTML and PHP, Java Script Click here to Update Your Picture
Sea Ansley
Date : Mar 30th 2002
Grade : 2 of 5 (graded 7 times)
Viewed : 22247
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Sea Ansley
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

(I originally posted this in the main PHP manual some time in early 2002 and an
article outlining this amongst other things may soon circulate somewhere on u-
magazine.com or elsewhere.)

I used some help from the web as far as the javascript element goes, but the rest is
my own strange reasoning.

I learned everything the hard way when moving to a server that was out of our time
zone, and discovered that all of the posts in our message board were three hours
behind us. I also got in a bit of an argument with one of the main PHP.net guys
about why "simple" things like this should be more important than functions like
Output Buffering.

Anyhow,

<?
//first lets introduce the main page displaying the local-to-user date and time. As
//I was working on forums scripts, lets call this forums.php the way our forums are
//constructed is that all the programming is done, then the layout is compiled and
//parsed in one giant template, which is very fast.

//This is part of the programming before the page template is parsed. If the user
//time zone cookie hasn't been set (on the first visit to a page, it won't have
//been), open the javascript include that will appear in the page's template :

if(!$usertimezone){

// special amendment for date/time conversion
// open javascript template/include

$checktimezone=parsetemplate("checktimezone");

// this javascript looks like this:

/* <script type="text/javascript">
now = new Date();
window.location.href="$PHP_SELF?tz=" + now.getTimezoneOffset();
</script>
*/

// somebody else created the script above. It makes sense though, on the first visit
// to the page, it automatically redirects to the same page, with the time zone
// variable ("tz") passed through the URL.

}elseif($tz){

// the next time a page in the forums has been accessed, and the cookie has not yet
// been set, set a cookie with the user's time zone (from GMT) AND create a variable
// for the time zone, because data in a cookie won't be seen until the next header
// request, and you want everything to take effect NOW.

$usertimezone=$tz;
setcookie("usertimezone",$usertimezone);

}

// next page is your functions page
// user date/time with local time zone

function userdate($format,$timestring){

// declare globals (that being the cookie and variable you have set)

global $usertimezone;

// convert user time zone into seconds

$timezone=$usertimezone*60;

// find timezone difference between server and UST in seconds

$difference=date("Z");

// difference between user and server

$usertime=$timestring-$difference-$timezone;

// return new value

return(date($format,$usertime));
}

// end user date/time
// then, when you want to display the date and time local to the user, you call it
// like this, just like you would a normal "date()" function, but allowing for the
// new function you have just created (assuming you used a time() string for your
// date):

$posttime = userdate($your_date_format,$time_of_post);

// I'm not sure why there isn't some way to read the time/date headers in a page
// request from the user's browser like you do with everything else in the language,
// compare that to the server's time, and exclude client-side programming
// altogether. If you can figure out a user's IP address, browser type and credit
// card number, you can certainly figure out the difference between their time and
// the server's.

// I have been using this date/time setup for a couple of months now, and to be
// honest, I had forgotten we even used it. This is a good thing, because at first I
// assumed it would all be a bit too distracting or annoying, but I was far wrong.



Validator 98 - a PHP-script to generate form-validation-code in JavaScript.
Categories : Complete Programs, Java Script, PHP, HTML and PHP
Dynamic Calendar in PHP, Javascript and HTML.
Categories : PHP, Java Script, HTML and PHP, Calendar
Dynamic generation of textboxes, select items etc in a table for use with databases applications, matrimonials and for job sites
Categories : PHP, HTML and PHP, Java Script
Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps.
Categories : HTML and PHP, PHP, MySQL, Date Time
This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field
Categories : PHP, MySQL, Java Script, HTML and PHP
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides
enhanced date picker with jcript checking for a dynamic date input
Categories : PHP, Java Script, Date Time, Calendar, Arrays
OverEasy - PHP generated JavaScript to do mouseovers on your pages. Modify one file and one function does it all for you!
Categories : PHP, Java Script, HTML and PHP, MySQL
Function that allows a Javascript cookie to be set after HTML has been outputted to the page.
Categories : PHP, Java Script, Cookies, HTML and PHP
Calendars to choose a range of dates , reservation events ...
Categories : PHP, Calendar, Java Script, Date Time
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time.
Categories : PHP, Calendar, Date Time, HTML and PHP
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS