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.
Related
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
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
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)
My date is ahead 1 hour when I post to mySQL via php. I'm in Los Angeles. How can i make the time correct?
Here is what I currently have:
$date = date("m/d/y g:i A") ;
Use this to get the time zone PHP is using date_default_timezone_get();
If you're in Los Angeles you can set your time zone temporarily for only the current script
date_default_timezone_set('America/Los_Angeles');
http://php.net/manual/en/function.date-default-timezone-set.php
Also pass T in the date function:
echo date("D M j G:i:s T Y"); outputs Mon May 25 16:23:49 EDT 2009
see
date_default_timezone_set
like
date_default_timezone_set('America/Los_Angeles');
First check if servers time is correct ( on linux use date shell command). If yes, you just set the time and you're good.
If not you have to change it in php with setlocale() or date_default_timezone_set() function
It depends on your specific case, but I had saved the date as UTC / GMT time, so I had to use the gmdate function instead of date. E.g.
gmdate("H:i",$time)
So the clock is 18:37 right now in sweden but it prints out 16:37 why is that?
$timestamp = time();
date('M d, H:i', $timestamp)
What can be wrong?
Your date.timezone setting in your php.ini file is incorrect. Make sure that it is set to the proper value for your timezone:
date.timezone = Europe/Stockholm
If you do not have access to the php.ini file, you can use date_default_timezone_set() to set it during runtime:
date_default_timezone_set('Europe/Stockholm');
For a list of supported timezones, refer to the PHP Documentation.
If it still doesn't work, make sure your server is set to the proper timezone. If you've set the time manually and the timezone is incorrect (but since the time has been corrected manually it still shows the proper time), PHP has no way to get the UTC time properly and therefore returns the incorrect time.
It is possible that your server is located in a time that is 2 hour back from you.
You can use this page of the documentation to fix the timezone issue.
Try a line like this:
date_default_timezone_set('America/New_York');
Except, y'know, for Sweden.