Jump to content

Inconsistent Times


penislandbic
 Share

Go to solution Solved by ginerjm,

Recommended Posts

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 by penislandbic
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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