I am getting Date & Time in UNIX Timestamp. So wanted to convert it to "America/Los_Angeles" Timezone in dd-mm-yyyy HH:MM:SS format.
How to do this in PHP ?
e.g: Input: 1345014000 Output: 15-08-2012 00:00:00
The date_default_timezone_set function can be used to set the current timezone within PHP. You need only call this once per file, as all calculations from then onwards will be done using that timezone. It accepts all valid timezone names, such as the one you mentioned.
The date function on the other hand, accepts a string explaining the format, and the timezone you wish to be converted. A full list of formatting options can be found at: http://php.net/manual/en/function.date.php
Usage in your situation would be as follows:
date_default_timezone_set("America/Los_Angeles");
$str=date('d-m-Y H:i:s',$timestamp); //Where $timestamp is the timestamp to be converted
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With