Correct time...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cyphonic
Forum Newbie
Posts: 13
Joined: Sun Aug 18, 2002 1:29 pm

Correct time...

Post by Cyphonic »

My site is hosted on a server in canada or something, and the time in Norway (where I live) is 2 hours ahead of the time in Canada! So how can i get the server to display the correct time, when the format is like this:

$time = date ("H:i:s");
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Easy get the number of hours and add on 2!
daemorhedron
Forum Commoner
Posts: 52
Joined: Tue Jul 23, 2002 11:03 am

Post by daemorhedron »

One method would be to simply do

$time = date ("H:i:s",time()+7200);

//format the date of the current time+2 hours

or you could look into gmdate().

HTH =)
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

Takuma's approach is not good, since (as everyone knows, this was a joke?) if you always add 2 hours to hour you can get time like 25:43:12....

Just pointed out that so nobody really uses that. Use daemorhedron's method: works always and is more efficient.

-9902468
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

localtime() user contributed notes
to set up berlin time it could look like this:

<?php
print "<HTML><body><pre>";

setlocale( "LC_ALL", "de_DE" );

putenv( "PHP_TZ=Europe/Berlin" );

$now = time();

print_r( localtime(time(),true) );
print_r( getdate() );

print date("H:i:s");
print date("T");

?>
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Oops... Sorry for the bad help... I should have thought more...

Volka can you tell me what's going on with your script cos I'm not following it. Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

it's setting the 'locals'-settings (number format, type of calendar,...) to german default and sets the timezone to Europe/Berlin (GMT+1 ?)

Didn't know the enviroment-var was 'PHP_TZ' - just a quotation from the user contributed notes ;)
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Thanks Volka but do you know where I can find out list of things like "de_DE" for different country? e.g. I want to know USA and Japan.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Fabian.Rodriguez@toxik.com
14-Dec-2000 07:19

Language information is defined by this RFC:
RFC1766 - Tags for the Identification of Languages
- http://www.ietf.org/rfc/rfc1766.txt

And the 2 letter codes come from:
ISO639: "Code for the representation of names of languages"
- http://www.w3.org/WAI/ER/IG/ert/iso639.htm
ISO3166-1: "English country names and code elements"
- http://www.din.de/gremien/nas/nabd/iso3 ... index.html

Also note that the language name can be used in full (ex: setlocale('LC_TIME','swedish'); ) . This full name comes from the latest mentioned file.
gosh, I like the online manual :D
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Thanks. :)
Post Reply