Creating a EDT (Eastern Daylight Time) - timestamp - php

I tried using the php function below to accomplish this, however, it returns a mounain time, timestamp. I was wondering if someone can help me understand how I change time zones, or if someone can help me correct this to EDT?
date("F j, Y, g:i a");

You can either set it locally in the script itself, by using the date_default_timezone_set() function:
http://php.net/manual/en/function.date-default-timezone-set.php
Or you can change it in your php.ini file, if you look for the line:
date.timezone
Edit: Here is a list of supported timezones, if you're not sure what yours should be called:
http://php.net/manual/en/timezones.php

Related

PHP date showing wrong time despite the timestamp being correct

I'm having a problem with the PHP date function which I've never had a problem with before.
The timestamp is entirely correct, however for some bizarre reason date() is outputting a time which does not correspond.
I have the following timestamp (and this is definitely the correct one - when I echo it out onto the page, as well as in the database, it shows as being correct):
464400
Yet when I use the following line of code:
<?php echo date("H:i",$timestamp); ?>
I'm getting a time of 4 am? If I paste the timestamp into a timestamp converter website, then it shows the time should in fact be 9am.
I'm completely stuck, this has never happened to me before & this problem has only just come up recently - the code hasn't been changed and everything seemed to be working correctly before.
Does anyone have any experience with this issue? Any help would be appreciated.
That time stamp is is 9am GMT timezone, if you are in another timezone then you will need to adjust it accordingly.
http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('Europe/London');
or even better in your php.ini
http://php.net/manual/en/datetime.configuration.php
date.timezone="Europe/London"
Or you can use more specifically GMT instead of Europe/London (which has DST)
try this method will work
for time zone
http://php.net/manual/en/timezones.php
code
<?php
date_default_timezone_set('Asia/Kolkata');
$dt2=date("Y-m-d H:i:s");
echo $dt2;
?>
try this
// set default timezone
date_default_timezone_set('UTC');
//define unix timestamp
$timestamp = 1456778973;
// output
echo date('d M Y H:i:s',$timestamp);
Try this converter too http://freeonlinetools24.com/
For time zone: https://www.php.net/manual/en/timezones.php
date_default_timezone_set('America/Chicago');
echo date("m/d/Y h:i:s A");

How to change time zone setting of server

I try to fetch date from server
date('l, F j, Y g:i A',strtotime($data_event->start_date));
It shows time zone EDT, how do i change it into Makkah Time zone. Please anyone out there for any suggestions.
Note: I prefer PHP language.
Thanks.
You can use
date_default_timezone_set('');
That should do it for all your PHP code.
If you are using a database, the timezone for the database will probably be different as well. If you are using MySQL, you have to SET time_zone = "+3:00" query as soon as you open a database connection.
Use date_default_timezone_set() for this
Also you can use Class datetimezone
List of timezones http://www.php.net/manual/en/timezones.php
I think the Asia/Riyadh will apply for Makkah Try this one,
<?php
date_default_timezone_set('Asia/Riyadh');
date('l, F j, Y g:i A',strtotime($data_event->start_date));
?>
You may try this one
SET time_zone = "+3:00"
in your index.php file. You don't need to have access to your php.ini file.

date() not the same as what's showing at my taskbar

This might be one of the stupidest question but....ok this is my code
date("l, M-d-Y, H:i:s")
but somehow the output shows when I run it through my computer instead of a server
Saturday, Feb-16-2013, 00:21:49
and my computer time is actually
Friday, Feb-15-2013, 16:21:49
and when I uploaded it into a server to try the code this is what it showed
Friday, Feb-15-2013, 19:21:59
Any reason why the date()is few hours ahead and the time is different when I upload to a server.....
I used the code P and e and Timezone identifier shows UTC with +00:00(GMT)
but I believe my GMT should be -08:00 or +08:00 I forgot.
Did I do anything wrong with the codes or just some settings I need to adjust with my computer? Because this happens to both my laptop and desktop.
Thanks in advance.
You should adjust timezone before accessing the date. In php there's a function to set the timezone
date_default_timezone_set("Asia/Calcutta"); //setting timezone
date("l, M-d-Y, H:i:s");
Here's the list of all timezone
http://php.net/manual/en/timezones.php
Check your php.ini for date.timezone:
http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
e.g. date.timezone = "Europe/Berlin"
or you can use
http://www.php.net/manual/en/function.date-default-timezone-set.php

php strtotime function showing 1 hour more

I am trying to convert 1355657846 and 1355677646 unix timestamp to Y-M-D H:i:s format.
The problem is in H:i:s . It should be
11:37:24 and 17:07:26 respectively but it is showing 12:37:24 and 18:07:26.
<?php
echo date('Y-m-d H:i:s','1355657846');//2012-12-16 12:37:26,must be 11:37:26
echo date('Y-m-d H:i:s','1355677646');//2012-12-16 18:07:26,must be 17:07:26
?>
It should be 11:37 and 17:07 because I checked it in unix timestamp conversion
and also it is the time I had received mail in gmail account. And I got these unix timestamp from gmail( using php imap function...$overview->udate)
I am testing this on local xampp server.
Can anyone suggest me where I am going wrong here?
PS: I checked related question in stackoverflow, but here I want to convert timestamp to datetime, which I think should be constant irrespective of timezone.
It is definetily the timezone setting in your local web server.
Check the php.ini for date.timezone value.
It also may be overridden by htaccess file or you PHP script.
strtotime was included once DateTime was created. The parsing is dependant of the server default timezone.
If you want get your date with the good timezone, there are two ways :
default_timezone_set('Europe/Paris');//for example
or :
$date = DateTime::createFromFormat('U',$timestamp,new DateTimezone('Europe/Paris'));
echo $date->format('Y-m-d H:i:s);
you can find more informations here .
This is probably due to the TimeZone setting. Learn about PHP date_default_timezone_set() and make sure your local time zone matches the timezone you really want. All Unix Timestamps are the same world-wide. But the local DATETIME values vary around the globe. This article may be visible to you (hope so):
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
Best regards, ~Ray

Php date function

I can't see my location time with following php function:
echo date("y-m-d h:m:s A");
it's show 12-05-05 08:05:12 AM BUT it's 12-05-05 12:40:12 PM NOW
Can anyoe fix this issue..
Thanks.
Set your preferred timezone in php.ini:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Manila
You can see the list of supported timezones here.
Or you can go other way, use date_default_timezone_set().
Set setlocale function. Here this the description
Fix your server time, or use this:
http://php.net/manual/en/function.date-default-timezone-set.php
You are using m, but it's used to represent month, not minutes.
This is probably what you'd like to do:
echo date("y-m-d h:i:s A");
After that, you're either using the wrong timezone or the servers time is badly setup. If you have access to the server run date in a terminal.
Apart from Blake comment, i suggets try fixing your time zone, add +/- time you require
time , example
$timediff = 10;
$diff= $timediff+ ($timediff* 60 * 60)

Categories