strtotime

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
User avatar
Sculpture
Forum Commoner
Posts: 41
Joined: Sat Jun 11, 2005 6:57 pm
Location: Australia
Contact:

strtotime

Post by Sculpture »

Hello,

Good grief...!

I have tried on several occasions to get my head around this one but to no avail. This is a piece of code that found on this forum.

Code: Select all

<?php
$currentdate = getdate(time());
$ausZone = strtotime('+ 15 hours',$currentdate);
?>
and imbedded in the body, in a hidden field in the body of html

Code: Select all

<input name="date" type="hidden" value="<?php echo "Application was lodged on ".$ausZone["wday"]." ".$ausZone["month"]." ".$ausZone["year"];?>">
Unfortunately it doesn't add fifteen hours to the timestamp.

Thanks ahead to anybody that can point me in the right direction.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

strtotime() doesn't accept getdate() output, but it does work with unix timestamps.
User avatar
Sculpture
Forum Commoner
Posts: 41
Joined: Sat Jun 11, 2005 6:57 pm
Location: Australia
Contact:

Post by Sculpture »

OK... new tact.

Let's say the server hosting the web site is in Texas and the people looking at the web site and retrieving the data are in Australia. They want to know when the form was submitted at the right time.

Has anybody got a straight forward, one size fits all, method to insert an adjusted the time at the Australian timezone, using PHP4?

Thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I would store everything in gm time ... and calculate the offset for us and au timezones (if i'm not mistaken strtotime is capable of doing this).
User avatar
Sculpture
Forum Commoner
Posts: 41
Joined: Sat Jun 11, 2005 6:57 pm
Location: Australia
Contact:

Post by Sculpture »

Yes thank you so much!

gmdate
ttech5593 at gmail dot com
29-Mar-2006 09:53
For me most of the examples here needed the + or - seconds to set the time zone. I wanted a faster way to get the time zone in seconds. So I created this :

Code: Select all

<?php 
$h = "3";// Hour for time zone goes here e.g. +7 or -4, just remove the + or -
$hm = $h * 60; 
$ms = $hm * 60;
$gmdate = gmdate("m/d/Y g:i:s A", time()-($ms)); // the "-" can be switched to a plus if that's what your time zone is.
echo "Your current time now is :  $gmdate . ";
?>
It works. Hope it helps.

You showed me the way and it works. :D
Post Reply