PrettyHugePecker Posted May 15, 2007 Share Posted May 15, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/51499-strtotime-problem/ Share on other sites More sharing options...
Daniel0 Posted May 15, 2007 Share Posted May 15, 2007 Why not just something like this to e.g. display their current time (based on a setting they have set containing the offset to GMT)? <?php $timezone = 1; // GMT +/- echo "TIME IS: ".gmdate('l F j, Y \a\\t g:i A', time()-3600*$timezone); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51499-strtotime-problem/#findComment-253624 Share on other sites More sharing options...
PrettyHugePecker Posted May 15, 2007 Author Share Posted May 15, 2007 Well the current time in their timezone is no problem. What I need is to convert a time that they specify. Quote Link to comment https://forums.phpfreaks.com/topic/51499-strtotime-problem/#findComment-253629 Share on other sites More sharing options...
Daniel0 Posted May 15, 2007 Share Posted May 15, 2007 Ah. Okay. Let's say I supply this line: 17:25 That is in GMT+1. In my settings on your system I set the timezone to be that (meaning that $timezone in the below example holds int 1). <?php //... $time_gmt = strtotime($_POST['when'])-3600*$timezone; //... ?> Quote Link to comment https://forums.phpfreaks.com/topic/51499-strtotime-problem/#findComment-253643 Share on other sites More sharing options...
PrettyHugePecker Posted May 15, 2007 Author Share Posted May 15, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/51499-strtotime-problem/#findComment-253678 Share on other sites More sharing options...
Ninjakreborn Posted May 15, 2007 Share Posted May 15, 2007 Hmm, so you really intend to let someone with that name run around on the boards, kid's come here too. Quote Link to comment https://forums.phpfreaks.com/topic/51499-strtotime-problem/#findComment-253704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.