Jump to content

Time Of Server


Sherder

Recommended Posts

It's hard to help you with only the information you provided. Can you give us an example of what your talking about and maybe the code?

 

BTW, the server is on Pacific Standard Time.

 

Okay, so I have added to my website a PHP code: $datetime = date("Y-m-d H:i:s")

 

When I put "echo" -command to the beginning it shows in my website time like "2011-11-29 21:24:48", but the problem is that time changes almost every time. I mean when I refresh the page it shows 2011-11-29 23:22:44 or 2011-11-30 06:21:21 and so on. So the problem must be at server. I don't even know how that is possible, because it shows the time of server. In my home computer it shows the time exactly correct and in other free web hosting site the time goes normally forward. Does your server change time constantly or something?

Link to comment
Share on other sites

For me it jumps 2 hours back and forward on your example.

If I refresh it many times then usually it shows time in GMT-0800 (PST), but sometimes in GMT-0600 (CST), while byron's page display time in GMT-0500 (EST).

 

Are you sure your script does not change the time zone used for some reason? putenv("TZ=XYZ");

Do you have the same results if you'll echo just the time with having nothing more in the script?

Eventually add to the script the following to confirm if the timezone is not switched:

echo getenv("TZ");

Link to comment
Share on other sites

I added putenv("TZ=XYZ") and getenv("TZ") to my website and I tested it again. The result was that the putenv and getenv did not change. It was only the time which changed... This is so unbelievable problem that I don't know how this could be solved. This is very strange. I can't make reliable system where I save users last activity to database etc.

 

You can try again:

http://intr.heliohost.org/index.php

 

 

Edit:Now I got for example:

2011-11-29 16:37:19

putenv("TZ=XYZ"): 1

getenv("TZ"): XYZ

Link to comment
Share on other sites

There is no such time zone like "XYZ". ; ) Sorry, that was just an example on my side.

You may want to put "TZ=EST" or "TZ=America/New_York" etc.

 

Place putenv("TZ=your_desired_timezone"); at the very beginning of your script and then the time for you should be displayed correctly (unless in some other place of your script you will change timezone again).

 

All valid time zones you can find here:

http://php.net/manual/en/timezones.php

 

 

But I'm curious... if YOU (your script) don't change timezone randomly... why is this changing by itself?... I may test it later.

Link to comment
Share on other sites

Oh, yeah, I'm so tired now because I'm from Finland and here is night at the moment :). I have never used those timezone PHP commands before.

 

But I have now added these in my website:

putenv("TZ=Europe/Helsinki"): 1

getenv("TZ"): Europe/Helsinki

2011-11-30 00:54:12

 

When I now test my website the time does not change or then I didn't test very well yet. But it seems to work now because of changing timezone at the very beginning of my script with that putenv("TZ=Europe/Helsinki"); :). I continue testing.

Link to comment
Share on other sites

Midnight for me in Poland. ; )

 

Anyway... additional note for you: Stevie's (the server your website is on) clock "jumps" back and forward 24 seconds (it's either correct or 24 seconds behind). Admins don't know why is that so far.

Default timezone being switched may be related to the same problem. I think I'll test it when I'll find a time and inclination.

Link to comment
Share on other sites

An easier way to set the time zone for your site would be to add this to your root htaccess file:

 

SetEnv TZ Europe/Helsinki

 

That's how I set my time zone to EST.

 

SetEnv TZ US/Eastern

 

Then you don't need to set it in any of your php scripts.

 

Link to comment
Share on other sites

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.   Paste as plain text instead

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