Jump to content

strtotime problem


Recommended Posts

Hello Mates!

 

I am having a problem getting consistent results with strtotime().  I am taking user input from a text box, and converting it into a timestamp in GMT.  Here is the code (I'm using PHP 4.4.4):

 

putenv("TZ=utc");
$timestamp = strtotime($_POST['when']);
echo "TIME IS: " . gmdate("l F j, Y \a\\t g:i A", $timestamp);

 

Right now it's 8am MST (GMT - 6 hours)

Whenever the time given is absolute, like "8am" the result is "TIME IS: Tuesday May 15, 2007 at 8:00 AM".

But when the time is something relative, like "now" the result is "TIME IS: Tuesday May 15, 2007 at 2:00 PM".

 

My problem is that I have an offset for all my users (e.g. -7 hours), I don't have their specific time zone.  So if I just add an offset, it won't be accurate when they say something like "8am".

Is there a way I can get accurate results for users in all time offsets, and all formats?

 

Thanks for your help!

Link to comment
https://forums.phpfreaks.com/topic/51499-strtotime-problem/
Share on other sites

Yes but this only works when they enter something like: "now", or "tomorrow".

If they enter something "8am" it doesn't work.

 

My guess why this is happening is that strtotime uses the timezone, only when it has a specific time.

Could it be that I'm not using the right value for UTC?

 

putenv("TZ=UTC");

 

Maybe this is incorrect and it is still using my default timezone?

 

Thanks again!

Link to comment
https://forums.phpfreaks.com/topic/51499-strtotime-problem/#findComment-253678
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.