I am having trouble in the timestamp.
When I am using the LAMP in Ubuntu, then it works with correct date which I entered, but on other systems it show 1 day back's date.
I don't know what I need to do now. I have stored the timestamp in my database. But when I am showing it on my web application, it works fine in the LAMP but not in others.
When I am converting the timezone to online converter it shows backdated result. What do I do now?
You can set PHP default timezone before reading the date from the timestamp.
Add the following line before reading the date.
date_default_timezone_set('Asia/Calcutta');
Let me know if this helps.
References:
http://php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/timezones.php
The timestamp stored is correct, Please set the default time zone in your PHP application to let the system know which timezone you are using then it will store the correct time zone. the below link would help you.
I am assuming you are storing timestamp in DB and retrieving it to display
http://php.net/manual/en/function.date-default-timezone-set.php
Thanks
Related
When I echo
date_default_timezone_get()
It echo's the server datetime instead of my current timezone. I wanted to have my real timezone.
How can I proceed with this.
You can set your default zone with:
date_default_timezone_set('America/Los_Angeles');
and get it:
$your_timezone = date_default_timezone_get();
Here you can check supported timezones.
PS: When you know how to set timezone, you can get users browser timezone, tutorial but you should use JS :)
i am using
date_default_timezone_set('Africa/Nairobi');
$date = date('Y-m-d H:i:s');
but its always returning date and time form my PC.
Ex.. today is - 15/07/2015
and i changed my PC date to 17/09/2016
so php Date also returning same date...(17/09/2016)
is there any why to get real time and date?
what i have tried
1. simple date function
2. set timezone
3. i have searched on google but no luck yet...
It will always return your PC date as it well should.
Date & time functions use the server's date and time. So if you're running a local server (WAMP, XAMP or whatever) your PC will be the server and therefore it's time will be used.
Setting the timezone should change the time accordingly though.
There is nothing wrong with your code
date_default_timezone_set('Africa/Nairobi');
$date = date('Y-m-d H:i:s');
but as #Rizier123 said that if you are using XAMPP or WAMP or any other local server it will show the system time only. I would like to suggest you that put your code to an online server or use some online php compiler, then it will surely gonna give you the expected output.
How to get correct date not by system date in php
For ex: actual date is 24/4/2013, but I changed my system date is 25/4/2013.
How can get correct date ie 24/4/2013?
PHP can't inherently know that your system time is incorrect. As others have pointed out, you can query an authoritative source (similar to the solution offered here) instead.
EDIT: shortcut to the time server query example
http://tf.nist.gov/tf-cgi/servers.cgi
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Set the default time zone prior to use the date() function.
For instance:
date_default_timezone_set('UTC');
// or
// date_default_timezone_set('Europe/Madrid')
echo date("Y-m-d H:i:s");
Timezones and timestamps confuses me so I'm hoping someone can answer my questions :)
Lets say I have a Python script that parses an RSS feed, converts the date value into a timestamp using the following code and stores it in a database:
article_date = parse(article.published).strftime('%s') if hasattr(article, 'published') else round(time.time())
Now when I retrieve that record from the db in PHP, and I run the following code, does PHP assume the timestamp was UTC-0 and automatically offsets the timezone to Eastern time?
date_default_timezone_set('America/New_York');
echo date('Y-m-d H:i:s',$timestamp);
I'm seeing weird issues with my dates, so I'm wondering if someone can help me out with advice on how to properly convert and store rss feed timestamps. I can across this line of code somewhere so should I put this at the top of my script?
os.environ['TZ'] = 'Europe/London'
If you want to set your timezones and keep them aligned in PHP and in Python, then your PHP code is completely correct and for python you need to apply the following:
os.environ['TZ'] = 'America/New_York'
time.tzset()
before you call strftime()
That should make sure you store the time in the same zone you're trying to retrieve it.
Note: tzset() is a Unix-only function.
I am using date() function it getting the date and time as per my given format but the time its showing me is 4 hours forward than my current local machine time:
This is my code
echo date("Y-m-d h:i:s", time());
Its showing me : 2009-10-28 08:47:42
Where as it should Disply : 2009-10-28 04:47:42
Any Idea whats wrong with this and why its showing different time.
it is likely giving you GMT, you need to set your timezone: e.g. date_default_timezone_set('America/Los_Angeles');
http://php.net/manual/en/function.date-default-timezone-set.php
Make sure your time zone is set correctly:
e.g.
date_default_timezone_set('UTC');
It's returning the timezone of your server, not your computer
try http://www.php.net/manual/en/function.date-default-timezone-set.php
Because you are in, probably, US/Eastern (America/New_York, currently EDT) time zone, but the PHP you are using is running in UTC. You need to ensure that the TZ variable is set in the PHP environment.