I want to display on my page the current date in this format: 22/02/2013 - 12:00 (day/month/year - hour)

I use strftime("%d/%b/%G - %R", time()) but shows nothing on the page. If I do

echo var_dump(strftime("%d/%b/%G - %R", time()))

it shows bool(false). Any idea what I'm doing wrong??

有帮助吗?

解决方案

Windows doesn't support %G or %R, you should use %Y and %H:%M respectively.

strftime("%d/%b/%Y - %H:%M")

其他提示

From the strftime() documentation:

As the output is dependent upon the underlying C library, some conversion specifiers are not supported. On Windows, supplying unknown conversion specifiers will result in 5 E_WARNING messages and return FALSE. On other operating systems you may not get any E_WARNING messages and the output may contain the conversion specifiers unconverted.

So, you are probably using unsupported format parameters.

Note: by default time() is used for a timestamp, so you can use strftime() with it if you require this defaul tiemstamp.

Try this:

echo date('d/m/Y - H:s');

If you need to, you can set the timezone like this:

date_default_timezone_set('UTC');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top