PHP Countdown added two hours - php

currentime=strtotime('22:00:00');
rem=currentime - strtotime('now'); //now is 20:00:00
remaining=date("H:i:s",rem);
My problem is, remaining shows 04:00:00 instead of 02:00:00
Is there any clue why it is? I also set date_default_timezone_set

Check your settings in php.ini file. There should be line similar to this one:
date.timezone = UTC
Try setting it to your time zone.

Related

php date can't get 24 digit time hour

I'm using date function $now=date("Y-m-d H:i:s"); in php 5.6.30,
The browser output is string(19) "2017-04-21 02:54:54",That's abnormal.
php.ini set is date.timezone = PRC
Centos 7 system time:
[root#localhost sync]# date
Fri Apr 21 14:53:20 CST 2017
While I was installed the PHP 7.0.16 in the same system, php.ini has the same config, but the date output normal in date function(is 24 digit time).
Why happen this and how to let the date normal working.
This is a timezone issue.
In your php.ini, you have the timezone PRC (China) set, but your system time output gives the time in CST (Amerika).
In other words:
Your PHP code does actually give you the 24-hour format, but in a different timezone, where it is in fact 02:54:54
If you need to get the time in a different timezone (like UTC), you can set it like that:
date_default_timezone_set('UTC');
If you need a different local timezone, you can read about the possible values in the list of supported timezones in the PHP documentation
try this below code for date timezone
<?php
date_default_timezone_set('Asia/Shanghai');
echo date("Y-m-d H:i:s");
?>
I'm add the code to php.ini date.timezone = Asia/Shanghai,
and install chrony and start it to synchronized. It works.

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 Setting Correct Time Zone

I have the following code
date("D j M g a", strtotime($start))." - " . date("ga", strtotime($finish));
`["Start"]=>
string(21) "/Date(1354323600000)/"
["End"]=>
string(21) "/Date(1354326300000)/"
}`
The above code outputs Thu 1 Jan 12 pm - 12pm" string(22) "Thu 1 Jan 12 pm - 12pm in the correct format that I want but how could I get the day date and time correct.
Pacific/Auckland is my timezone
The issue is that what you pass to the strtotime - /Date(1354323600000)/ string is not in a valid format for strtotime function.
And actually it's a regular unix timestamp in milliseconds.
So the obvious solution - is to clean up everything but numbers and divide it by 1000:
$unix_time_with_ms = preg_replace('~\D~', '', $date);
echo date('Y-m-d H:i:s', $unix_time_with_ms / 1000);
Prefer setting default timezone in your php.ini file with a line like this:
date.timezone = "Pacific/Auckland"
If for some reason you can't edit php.ini then on top of your PHP script you can set a timezone (effective for that script only):
date_default_timezone_set('Pacific/Auckland');
You can set time zone using
date_default_timezone_set('America/Los_Angeles');
More Link
if you want to set in the script try
date_default_timezone_set — Sets the default timezone used by all date/time functions in a script
date_default_timezone_set('America/Los_Angeles');
but if you want to use the same time zone than setting in php.ini will be better solution
date.timezone = "America/Los_Angeles"

PHP date behaving incorrect

I don't know what I am missing but PHP's date function is behaving very incorrectly.
The date on my PC shows 26th October 2011, 11:32 AM but when I do:
var_dump(date('Y-m-d H:i:s'));
I get 2011-10-26 06:02:28
What is happening? This is driving me nuts.
You must change your date.timezone in php.ini.
Here's a list of the available timezones for PHP
Don't forget to restart your server after a new timezone is set.
I think it's a problem with the time zone settings
try some thing like that
date_default_timezone_set('Europe/Dublin');

Php clock 2 hours back

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.

Categories