Jump to content
xisto Community
Sign in to follow this  
rvovk

Php Time ...how to set OFFSET fot your timezone..

Recommended Posts

So this the code for displaying us time in San Francisco-USA where servers of Xisto are located and Slovenia-Europe (nine hours ahead of San Francisco):

 

<?php$server = date("F j, Y, g:i a"); // USA?><?php$myplace = date("F j, Y, g:i a", time() + 32400); // Slovenia?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;<html><head><title>Kulturno umetniko drutvo Godba na pihala Črnomelj - Kontakt.</title></head><body><?php echo $myplace;?><br /><br /><?php echo $server;?></body></html>

So this code defines local time that is set on server where you are hosted:

 

$server = date("F j, Y, g:i a"); // USA

This code defines time offset (e.g. time in your country, + or - hours depends on where you are living), we are 9 hours ahead San Francisco so we will embed code in prior time format like this:

 

$myplace = date("F j, Y, g:i a", time() + 32400); // Slovenia

Into prior code we added string:

 

time() + 32400

Which means we added 32400 seconds what is actually 9hours (*60minutes*60seconds= 9*60*60=32400seconds)

 

For displaying our strings in document we are using this code:

 

<?php echo $myplace;?><br /><br /><?php echo $server;?>

I found out how this works while fixing my guestbook and time entries which were 9 hours late. So this will solve most of your problems regarding this issue.

 

Working example of this code: here.

 

I better be going back to sleep, it is 5AM. :)

 

Notice from cmatcmextra:
Fixed broken link. (Changed directory /tutorial/ to /tutorials/)

Edited by cmatcmextra (see edit history)

Share this post


Link to post
Share on other sites

To add to this.

F = The full name of the month (January-December)j = Day of the month without a leading zero (1-31)
Y = The year as a 4-digit number (e.g. 2003)
g = The hour in 12-hour format without a leading zero (1-12)
i = The minutes with a leading zero (00-59)
a = "am" or "pm"


Share this post


Link to post
Share on other sites

David...Do NOT spam please. This is a pretty good tut for beginners, even though i didnt know how many seconds made w/e hours. Ill try using this in one of my sites, thanks for the tut.

Share this post


Link to post
Share on other sites

lol, you dont understand php at all the. PHP is software that needs to be installed on the web server, it processes the php code and gives a html output for the browser to read ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.