Jump to content

Format timestamp to timezone


newbtophp

Recommended Posts

I have an idea, which I'm trying to realise, im using the time() function to store the timestamp within my db...and within the db I have a timezone column (which contains the timezone selected by that user).

 

So I'd like to display $row['timestamp'] (the stored timestamp generated by time()) to the specified timezone, how would that work?

 

<?php
//$timestamp = timestamp generated by the time() function
//$timezone = the timezone to convert $timestamp too

function convert_time($timestamp, $timezone) {
//$new_timestamp = do something to adapt $timestamp to $timezone

//return the formatted/readable date...
return date('D M Y H:i', $new_timestamp);
}

?>

Link to comment
https://forums.phpfreaks.com/topic/210516-format-timestamp-to-timezone/
Share on other sites

Too bad you didn't store the time using a DATETIME or mysql TIMESTAMP, because you can do this directly in your query using the mysql CONVERT_TZ() function -

CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');

 

You could probably use the mysql FROM_UNIXTIME() function to get your data into a format that would work.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.