English 中文(简体)
为什么网站和日期不准确?
原标题:why does the date php and date unix does not match?

I have centos server and i rechanged the time to NewYork time by date cmd. Also i change in php.ini the "date.timezone = "America/New_York"" When i enter the command date in the command shell. i get the real time in new york. But when I do

对应日期:“Y-m-d H:i:s”

The time isn t right! I always get 6 hours less then the time in New York. Please help? I tried already using date_default_timezone_set( America/New_York ); in the code with no help. waiting for a response. Thanks! Koren Or

问题回答

i 更改时间,按日期分数计算

指挥日期为改变时间区提供了手段。 你也许会把它定在新航程时,但是,无论它已经安排了什么时间,因此,随着服务器时间的中断,你最终将达到6小时(奇怪的是,如果它走高路的话,它就应该是5小时。

Set the TZ environment variable export TZ=America/New_York before setting the time with the date command. Having an incorrect server time can lead to serious problems.

You can initialize the timezone in your app. What happens when you do this?

date_default_timezone_set( America/New_York );
echo date("Y-m-d H:i:s");

i change in php.ini the "date.timezone = "America/New_York""

Look, it is very common fault of people who aren t familiar with a formal logic.
Let me show you using a little example:

Suppose you just put some money into your pocket.
I come across and asks you if you got any money in your pocket. You says "Yes".

But you can t say it for sure! You can tell for sure only that you put it there. But there can be a hole in the pocket or some thief picked it already or you just confused pockets. So, you have to check it first, and answer later.

Although it is negligible in the real world, in programming such a behavior become critical! You can change whatever settings but you have to verify, if your actions had any effect
There can be an apache reload issue, or wrong ini.file or some runtime setting overwriting it.

Tl:dr
Always verify your settings, variables, data - if it really contains expected value!
Do not rely on the fact you changed it somewhere.

This sounds like an issue with not actually setting the timezone correctly on your machine.

First, to verify PHP is using the correct timezone, try the following to see.

echo date("Y-m-d H:i:s e");

如果你把“America/New York”正确地写进你的文字,那就应当给你“。

如果是的话,我将尝试讨论以下程序:here,以改变贵系统的时间,并看看这一工程是否可行。

我只想到这里,但你是否重新启用了你的藏书服务器?





相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签