Jump to content

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.

 

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.