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.
Related
Hello!
I set an ACF called pst_date and filled it with '03.05.2015' on a post.
In my template I'm using:
<?php echo get_field('pst_date'); ?>
Output shows 02.05.2015.
Same happens for other years even 2020.
Now I was curious and tried other dates and both input '29.03.2015' and '30.03.2015' have same output of '29.03.2015'.
Before the date '29.03.2015' it shows the correct date.
After '29.03.2015' it is one day short.
Same happens for other dates passed the last sunday of march.
So I assume its some DST bug.
Is there any workaround / fix?
Google was not helpful with that particular problem.
wordpress 5.3.2
php 7.0 / 7.1 / 7.2 / 7.3
Thank you.
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
I have included a php file in my wordpress website. In the php file, I am getting the current time (in my current time zone) like this:
$time = date('Y-m-d H:i:s');
var_dump($time); die(date_default_timezone_get());
The date comes correct however the time is wrong and the time zone comes as UTC which is also wrong. Here is the result of var_dump():
string(19) "2015-09-21 01:32:24" UTC
I have checked all of the posts in stackoverflow regarding getting current time. Some developers have suggested below function if you are using WordPress which I tried and it is still giving the wrong time:
$time= current_time('timestamp', true );
I appreciate any guidance or solution.
Before your other code, set your desired time zone using
date_default_timezone_set ('America/Toronto');
See the list of supported time zones.
Sorry if this seems like a stupid question. I'm probably missing something obvious but I've been struggling with this for ages and am getting nowhere. I've tried searching but haven't been able to find anything specific enough so I'm asking here in the hope that someone smarter than me can help me out.
I'm using the following line of PHP code to get the timestamp of the beggining of the current week.
strtotime(date('o-\\WW', time()));
This works fine on my local server and it worked fine on my live shared hosting, but now that I have moved my site to a virtual dedicated server it returns a blank.
The date() part is working fine on all servers ie.
date('o-\\WW', time()) today returns 2012-W11 on all servers
Therefore the problem is with the way strtotime turns 2012-W11 into a timestamp ie a problem with running strtotime('2012-W11')
I'm guessing there must be a difference in the way the new virtual dedicated server is set up that is causing it not to be able to do this in the expected way but I can't for the life of me work out what it is.
Thanks in advance for your help
try changing the format to strtotime('2012 +11 weeks')
you can use below code get first day of the current week
$weekFirstDay = strtotime('Monday this week');
it's from PHP Manaul
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.