penislandbic Posted January 7, 2014 Share Posted January 7, 2014 (edited) My php script always returns different times. Example: The current time is 4:33pm and the script returns 11:33am. Then sometimes it is correct, and then randomly switches to something like 7:33pm when it should be 5:33pm. This is my code $time = new DateTime(); $time->setTimezone(new DateTimeZone('America/Chicago')); $time = $time->format('g:i A'); echo $time; I don't know if makes any difference, but I'm renting a server from Go Daddy for my website and it is running Linux. How would I fix this problem? Edit: I'm also having a problem with the "time()" function giving results that are hours off. Edited January 7, 2014 by penislandbic Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 7, 2014 Share Posted January 7, 2014 You should be setting your default time zone setting in your php.ini. I think that would solve this. At least include it in a generic startup 'include' in all your scripts. Actually, I believe that php gives you an error/warning when you try to use a data/time function and you don't have it set. Sorry to hear that you've hitched yourself to GoDaddy. Quote Link to comment Share on other sites More sharing options...
penislandbic Posted January 7, 2014 Author Share Posted January 7, 2014 You should be setting your default time zone setting in your php.ini. I think that would solve this. At least include it in a generic startup 'include' in all your scripts. Actually, I believe that php gives you an error/warning when you try to use a data/time function and you don't have it set. Sorry to hear that you've hitched yourself to GoDaddy. How would I change my php.ini to the correct time zone? I have no clue what a php.ini is. I googled it and read that I also have to restart the server. How would I do that? I am sorry about signing up for a year with GoDaddy also. Do you have any suggestions for good hosting serveces? Quote Link to comment Share on other sites More sharing options...
Solution ginerjm Posted January 7, 2014 Solution Share Posted January 7, 2014 What timezone do you want to use? Or is it based on the location of the client? PHP is going to give you the time that is set in the .ini file, which probably is related to the location of the server farm. If you're not setting it, then perhaps the default is set by GD and you should use phpinfo to determine what it is. If it's not what you want, read up on how to modify php.ini settings. (Hint: search the php manual) I'm no expert on handling times in zones related to the client, so I may be of no help here. But if you are the one seeing the problem, I think it's what I said above. Quote Link to comment 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.