[Php] Using GMT instead of server time

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Alex.

Account Closed
Impact
5
is there a way to request gmt time, or do you need to manually increment the hours?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You can change the timezone by using the date function however this is repetitive and unnecessary.

You can use a function called putenv to change the server time.

Example:
PHP:
putenv("TZ=Europe/London");

//  Below would output GMT time:   
//  echo date('h:i:s');


Add it to the top of your script or before any time/date functions that will need to use the new timezone.

Matt.
 
Last edited:
0
•••
when you say change, do you mean convert the time php reads from the server to gmt?
not actually changing the physical server time
 
0
•••
By change i mean that code will actually change the timezone for the length of the scripts execution (it then reverts back) :) It doesn't technically change anything, but you get the idea.

do you mean convert the time php reads from the server to gmt

In a few words yes.
 
0
•••
ah, i see.
thanks very much
 
0
•••
Alternatively, you can use the gmdate function:
Code:
<?php
gmdate('h:i:s A');
?>
 
0
•••
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
URLs.com
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back