Time offset on timestamp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
richardk
Forum Newbie
Posts: 4
Joined: Thu Jun 05, 2008 11:07 pm

Time offset on timestamp

Post by richardk »

I am trying to add a time offset (+1hr) to this script; can anybody help. The server that hosts this page is in another time zone.

<?php
$filename = 'weather1.txt';
if (file_exists($filename)) {
echo "Last Updated: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>

I am takeing a time stamp off the file being uploaded so people looking at the web page can see if the file has been updated as it should be via FTP.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Time offset on timestamp

Post by susrisha »

Code: Select all

 
$date = strtotime(date("F d Y H:i:s", strtotime($date_from)) . " +1 hour");
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Time offset on timestamp

Post by pickle »

susrisha wrote:

Code: Select all

 $date = strtotime(date("F d Y H:i:s", strtotime($date_from)) . " +1 hour"); 
The order of arguments is wrong there, and you don't need 2 calls to strtotime().

Use this:

Code: Select all

$date = date("F d Y H:i:s",strtotime('+1 hour', filemtime($filename)));
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply