php中的time()函数表示当前时间是1970年
I am running XAMPP on mac.
I have a very simple script:
<?php
echo time();
always returns time in the 1970.
example: 1475044574 (Edit: 1475137157)
I tried setting the timezone in php.ini and then calling date_default_timezone_get() and it returns the correct set value.
I tried adding SetEnv TZ MyTimezone to httpd.conf (at the bottom of the file) and it did not work.
I also tried setting the timezone in php with date_default_timezone_set() and though it sets successfully, time is still in 1970.
I tried the same script on MAMP and still the same problem.
Any suggestion is appreciated!
time function is returning proper unix timestamp you are doing mistake in converting time into proper format. 1475044574 means Wed, 28 Sep 2016 06:36:14 GMT which is correct.
You can convert time as you want. refer date formats.
check this sample code :
echo date('M j Y g:i A', 1475044574);
Bro, as per PHP manual php.net/manual/en/function.time.php time() function returns seconds not miliseconds. Please check timestamp your timestamp on this site epochconverter.com.
time()
function returns current Unix timestamp
. So, your 1475044574
is a timestamp.
Using date
function you can see that this is a timestamp of (some variations with timezones, results may vary):
echo date('Y-m-d H:i:s', 1475044574);
// 2016-09-28 02:36:14
If you convert this timestamp to some string representation and get something like 00-00-1970
- you obviously do the conversion wrong.