i am storing member's created date using the time() function, and echo them back using strftime() and the date() function, but it doesnt display the right time information
my code is :
date("d-m-Y H:i:s", $member->created)
strftime("%Y-%m-%d",$member->created)
it should have displayed this:
17-11-2010 14:42
rather than:
17-11-2010 23:45
now, i have change my php.ini date.timezone configuration into my current time zone which is "Asia/Jakarta", yet nothing change. i have also try to set them manually inside my code using
date_default_timezone_set("Asia/Jakarta");
what did i miss ? please help me
Regards
EDIT:
according to Noodles, i need to check the server's clock setting, so i did using the
hwclock command, and it turns out that the clock setting is not right, since it displayed
Thu 18 Nov 2010 02:07:25 AM WIT -0.931691 seconds
while it should have been
Wed 17 Nov 2010 05:04:ss PM
now, how can i syncronize this setting into my timezone ??
Edit: i have manage to change the clock setting using
date -s "HH:MM:SS"
hwclock --systohc
thanks for pointing me out Noodles
case is closed i guess :D
thanks again guys
Are you sure your server's clock is set correctly? It would seem weird that the minutes would change. At the most I'd expect the hours to change if it was a different time zone, but not minutes.
Related
I am facing an issue in strtotime() in wordpress, that it is subtracting the hours according to my configured local timezone.
For example i tried strtotime("2021-11-16 00:00:00") on online php compiler it shows...
1637020800
but when i run the same on my wordpress site, var_dump(strtotime("2021-11-16 00:00:00")); it shows:
1637002800
which is wrong it is subtracting 5 hours as i set GMT+5 in my general settings.
I tried current_time('timestamp') but it won't help
Please can anyone help?
i found the problem in wordpress version 5.4.2, so basically in time zone if you select city,country it shows you this problem.
While if you select like GMT +5 etc it will show correct.
So i change Karachi to GMT+5 which make it sorted.
I generate a unix-timestamp in the adminpanel of my site with a modified version of the jquery datetime-picker.
This timestamp get's saved into a mySQL database and in the frontend I output it via the strftime() function.
As the site has multiple admins and everybody began to add content, I encountered an offset of 1h in the output time, due to the timezone we're in (GMT+1). Because content was already added, I couldn't edit the function which generates the date and writes it to the db, so I had to edit the output function in the frontend.
I thought it would be clever to just add (myTime+3600) as an argument of the strftime function. Everything worked fine and more content got added.
Now the problem is, that all content assigned a date in april 2013 is an hour to late because of the Daylight saving time.
I only have the timestamp to work with so I somehow need to get whether a date needs the 1h offset or not. Any ideas on how to do that without adding a timezone at the timestamp generating function?
There is a function.
Any recommendations are welcome!
Example:
frontend-code:
strftime("%d. %B %Y / %H:%M Uhr",new_timestamp+3600);
For 13.March 2013 16:30 I get the correct output.
For 13. April 2013 16:30 I get 17:30
set the application default timezone using this http://php.net/manual/en/function.date-default-timezone-set.php that way regardless of what timezone the client is in it should force the timestamps into your primary timezone.
You may also need to edit the datetimepicker inits to force jquery to use the server based timezone too.
I'm using this great jQuery timepicker http://trentrichardson.com/examples/timepicker/
It gives a string something like 07/20/2011 01:13 am
I have this situation where users on the site can schedule "events" and they are using this to pick the event. But im realizing that it could cause a lot of confusion with all the different timezones that people will be submitting from.
So I was thinking I could use php to somehow get the timezone, and the adjust how the viewer views the dates according to their timezone. But this seems like quite a task and was wondering if there was an easier way?
Also, even with the php idea I tried echo date_default_timezone_get(); as a test to see if it got my timezone, but its saying im in the Los Angelas timezone, rather than Baltimore/DC timezone.
I'm guessing its getting the timezone of my server since php is serverside.
So basically, whats the best way while using my time picker jquery script, that I can have all the users view the date/times adjusted to their timezones? Any help would be greatly appreciated.
when you get the datetime from user, save in a default timezone (GMT 0 for example), you need to know the user timezone.
When you get the datetime from DB, add the user timezone to it.
You are right, the default timezone is the server's.
get user timezone
you can save it in cookie
The term is UTC Time, Universal Coordinated Time. Googling that will find you a lot, in the meantime:
http://www.w3schools.com/jsref/jsref_getutcdate.asp
Direct give the UTC time (e.g. "Wed, 20 Jul 2011 06:10:38 GMT") to the users and use JS to convert it to their local times.
var localTime = new Date("Wed, 20 Jul 2011 06:10:38 GMT");
alert(localTime); // shows local time like: "Wed Jul 20 2011 14:10:38 GMT+0800 (CST)"
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.
I changed the timezone setting on my php.ini (xampp server) to date.timezone=Asia/Kolkata.
On my index.php I have this
date_default_timezone_set("Asia/Kolkata");
echo date('d-m-Y H:i:sa');
Result, I get is, 12-08-2015 11:42:49am, where as the actual date time at the time of running this script is 11-08-2015 11:12pm.
The date and time is like 12 hours apart from what actually it is.
Can you help.
Check your system time, date and timezone in the windows control panel. Make sure it is accurate.