STaRDoGG Posted November 8, 2009 Share Posted November 8, 2009 Hey all, I'm playing around with some code, and basically the idea is: Person changes their profile I fetch some XML that has a unix timestamp for the time the person changed their profile, so it'll keep increasing everytime I fetch the XML. It looks like this: <profileTime>12086</profileTime> I then run it through a function to convert the unix time to hours:mins:secs Finally I run it through another function to calc how long in the past that was, so it can be displayed in a user friendly format. The issue is, every time I run it through the second function, the final displayed time keeps increasing, rather than staying the same, which it should stay the same, because the person only changed their profile once, at that original time. Here is the first function, where I convert the unix time to h:m:s: function convert($sec, $padHours = false) { $hms = null; $hours = intval(intval($sec) / 3600); $hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':' : $hours. ':'; $minutes = intval(($sec / 60) % 60); $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':'; $seconds = intval($sec % 60); $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT); return $hms; } And here's the code in teh second function to format it: function olddate($hours, $minutes, $seconds) { /* List of working timezones here: * * http://www.php.net/manual/en/timezones.php */ date_default_timezone_set('America/Chicago'); // Calculate the exact day and time the status message was set $pf_time = strtotime("-".$hours." hours ".$minutes." minutes ".$seconds." seconds"); echo date("D F j, Y, g:i (s) a", $pf_time); //return date("D F j, Y, g:i (s) a", $pf_time); } Anyone able to offer any advice? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/ Share on other sites More sharing options...
MadTechie Posted November 8, 2009 Share Posted November 8, 2009 Why don't use just use date ie $time = 12086; date_default_timezone_set('UTC'); echo date("H:i:s",$time); Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-953458 Share on other sites More sharing options...
STaRDoGG Posted November 9, 2009 Author Share Posted November 9, 2009 Why don't use just use date ie $time = 12086; date_default_timezone_set('UTC'); echo date("H:i:s",$time); I'm using Date at the bottom of the second function, but I need to calc how long ago in the past it was first. I use date to format the results. The only thing I'm thinking is possibly the conversion in the first function is causing the problem? Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-953981 Share on other sites More sharing options...
MadTechie Posted November 9, 2009 Share Posted November 9, 2009 can you give me an example of what your trying to do Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-954173 Share on other sites More sharing options...
STaRDoGG Posted November 9, 2009 Author Share Posted November 9, 2009 can you give me an example of what your trying to do Do you want me to send you the actual php file? Other than having the actual php file, the code in the original post is about all there is to it, as far as the problem functions go. I can email you the file itself if you want to pm me an email address. Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-954442 Share on other sites More sharing options...
MadTechie Posted November 10, 2009 Share Posted November 10, 2009 No, I mean can you give me an example of what it suppose to do, basically this part id unclear Finally I run it through another function to calc how long in the past that was, so it can be displayed in a user friendly format. The problem is 12086 is a time stamp, not a date stamp.. so are you only working on a day by day basis ? if that's true then you could do this:~ date_default_timezone_set('UTC'); echo date("H:i:s",time()-$time); but i think i am missing something! Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-954502 Share on other sites More sharing options...
STaRDoGG Posted November 10, 2009 Author Share Posted November 10, 2009 Hmmm, ok. I am fetching an Aol instant messenger XML file, with a list of screen names in the XML, with each one's specific info in the nodes. When any of the screen names changes their Status Message, AIM sets a unix timestamp on it, so I would assume, that even though the timestamp will grow in number (due to the passage of time since it's been set), if I do a calculation using strtotime, to figure out how far in the past it calculates to, it should always show the exact same time/date it was set, until the user changes their Status Message again. My problem so far is: I run it through 2 separate functions, the first, converts the Unix Timestamp into hours, minutes and seconds, returning a format like this: 12:35:45 After I get those numbers back, I send it through the second function with those numbers ($hours = 12, $minutes = 35, $seconds = 45) Then I;m using the strtotime to subtract that amount of time from the current timestamp, and finally, using Date to show it in a more user friendly format, like: Status Message Set on: Thu Dec 12, 2009, 12:35 (45) pm It seems to set to correct time after running through both functions the very first run-through, however, any refresh of the page will add however many seconds, minutes, etc. that have passed since I ran it through the original time, rather than staticly show the same exact timestamp no matter how many refreshes. So to sum up, basically, if I'm on AIM and change my status message, no matte rhow much time passes, my timestamp will always remain the same until I change it again. My code isn't keeping it set to the same time, it keeps increasing as I hit refresh for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-954554 Share on other sites More sharing options...
MadTechie Posted November 10, 2009 Share Posted November 10, 2009 I would assume that the time would from AOL would be the amount of time they have been away for. 1 = 1 second 120 = 2 minutes etc. in that case, you could only really get a true time by pulling the xml every few minutes to check if they are still away Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-954559 Share on other sites More sharing options...
STaRDoGG Posted November 11, 2009 Author Share Posted November 11, 2009 I have the page set to meta refresh every 2 minutes or so already. But like I said, the time keeps changing rather than staying the same, like I want it to/it should. Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-955390 Share on other sites More sharing options...
MadTechie Posted November 11, 2009 Share Posted November 11, 2009 If its changing then its likely it uses the logic i stated in my last post.. the XML is updating a counter of time passed since last active Quote Link to comment https://forums.phpfreaks.com/topic/180711-strtotime-issue/#findComment-955394 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.