Nov 8, 2009

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

free web hosting
Open Discussion > MODERATED AREA > Tutorials

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

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

CODE

<?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 umetniško društvo 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:

CODE
$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:

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


Into prior code we added string:

CODE
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:

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. wink.gif

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

 

 

 


Comment/Reply (w/o sign-up)

truefusion
To add to this.

QUOTE
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"

Comment/Reply (w/o sign-up)

David789
I wouldnt know.

Comment/Reply (w/o sign-up)

Damann
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.

Comment/Reply (w/o sign-up)

cragllo
Thank you ver much for this, i have often wondered about setting offsets.

Comment/Reply (w/o sign-up)

neokid
Awesome script, which php verssion though? I have a domain and it wont work without arguing dry.gif

Comment/Reply (w/o sign-up)

cragllo
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 wink.gif

Comment/Reply (w/o sign-up)

pingusurf
Its nice and thanks. Can you work up for the IP address tracking? I have one but it dosent works.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Php Offset Fot Timezone


    Looking for php, time, set, offset, fot, timezone

Searching Video's for php, time, set, offset, fot, timezone
See Also,
advertisement


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

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com