Jump to content

How to convert datetime to another datetimezone in php???


hmdnawaz

Recommended Posts

I have a varaiable which gets the server time;

$date =date("Y-m-d H:i:s");

suppose the server is in the USA then it the timezone of this date will be the timezone of USA.

 

And i want to convert this timezone to Asia/Karachi timezone.

 

Any Idea about this???

Link to comment
Share on other sites

putenv adds setting to the server environment. The environment variable will only exist for the duration of the current request. At the end of the request the environment is restored to its original state.

 

so the code would be

-set timezone first to Asia/Karachi

-set $date as the current time in Asia/Karachi (this happens because the server environment is now set to that timezone)

-print out the date and time

 

putenv("TZ=Asia/Karachi");
$date=date("Y-m-d H:i:s");
echo $date;

 

thats all you need to do

 

all the available timezones are here

 

http://php.net/manual/en/timezones.asia.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.