Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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