views:

169

answers:

1

I'm pulling the most recent listened tracks from last.fm and putting them on my website.

Problem is, the times are retrieved in UTC-0 uts format and appear to be an hour out when comparing them to BST times in order to calculate a fuzzy time stamp ("about 5mins ago", "about an hour ago" etc).

Is there any way solve this so the times always match BST/GMT and adjust when entering and leaving daylight saving time?

Here's a snippet of PHP code i'm using at the moment, which results in the times being an hour out.

    $now = time();  // use this so all times are to the same second 
    $tz = getenv("TZ"); // save local setting so we can reset it later
    putenv("TZ=Europe/London"); 

    $trackPlayedAt = date('d M Y H:i:s', $track->date->uts);
A: 

date() automatically formats to the local timezone. The timezone depends on the configuration of the PHP server. If everything is set correctly, it should just work.

If you are running PHP 5.3 you have more options. Comment with which version of PHP you are running.

Jason McCreary
Ah i have PHP 5.2.6
Scotty
You're right! The script works fine on my hosting, but isn't working fine on my local MAMP setup. I'm not too sure how to configure it though :S
Scotty
Cool. Yeah, dates can be funny if you try to hard. I decided years ago to just let `date()` do it's think. You can verify the timezone setting in your php.ini or run `phpinfo()`. You are probably just missing DST or something.
Jason McCreary