I'm using the Twitter API to show my latest tweets on my website using PHP.
This is the part where I show the timestamp:
echo '<time data-original="'.$tweets[$i]['created_at'].'" title="'.date('l, j F Y', strtotime($tweets[$i]['created_at'])).' at '.date('g:ia', strtotime($tweets[$i]['created_at'])).'" datetime="' .date('Y-m-d', strtotime($tweets[$i]['created_at'])). 'T' . date('H:i:s', strtotime($tweets[$i]['created_at'])). 'Z" pubdate>"';
What I have noticed is that the dates are incorrect. For example for a tweet that was ACTUALLY posted at 11.51pm the following is parsed by the above code:
<time data-original="Sun May 04 22:51:43 +0000 2014" title="Sunday, 4 May 2014 at 3:51pm" datetime="2014-05-04T15:51:43Z" pubdate=""><a target="_blank" href="#">19 hours ago</a></time>
So first of all the data-original is one hour out (perhaps due to DST, but why hasn't the API handled this? As it knows my location via my timezone settings right?).
The second issue is that due to me formatting the dates in a certain way it seems to be switching the dates to the location of the hosting server so moving them back several hours.
Any ideas on how to fix this?
What I'm trying using JavaScript:
var d = new Date();
var n = d.getTimezoneOffset();
$('time').each(function(){
var time = $(this);
var timeOriginal = time.attr('data-original');
var timeDateTime = time.attr('datetime');
var timeTitle = time.attr('title');
var timeText = time.find('a').html(); // because the text is inside an anchor
timeOriginal = '';
timeDateTime = '';
timeTitle = '';
timeText = '';
});
So using that offset declared at the top of the page, I need to update the times so they become local rather than the server times. Not quite sure how best to approach this.