简体   繁体   English

PHP Log输出格式化日期

[英]PHP Log output formatted date

I want to write some logs to a file via PHP but when I want to output the date I don't find anything "standard" to simply write a complete date like : Wed Aug 13 12:38:02 2014 (and with the timezone, etc). 我想通过PHP将一些日志写入文件,但是当我想输出日期时,我找不到任何“标准”来简单地写一个完整的日期,例如:2014年8月13日星期三12:38:02(以及时区)等)。

I found a lot of examples with the date() function but you have to pass a lot of args (and I'm not sure if it's standard). 我发现了很多带有date()函数的示例,但是您必须传递很多args(而且我不确定它是否是标准的)。 By standard I mean something POSIX compliant (or something similar), understood by any program which want to parse this log file. 按标准,我的意思是某种POSIX兼容(或类似的东西),任何要解析此日志文件的程序都可以理解。

It is up to you how to format the date. 如何确定日期格式由您决定。 Actually, the date function is pretty easy to handle. 实际上, date函数很容易处理。

echo date("Y-m-d") // will output: 2014-08-13
echo date("Y-m-d H:i") // will output: 2014-08-13 16:25

the date function accepts a 2nd parameter, which is by default time() (so the actual timestamp). date函数接受第二个参数,默认情况下为time() (因此为实际时间戳记)。

You can specifiy the output by just adding the / changing the parameters in the brackets. 您可以仅通过添加/更改方括号中的参数来指定输出。 For example: 例如:

echo date("d.m.Y") // will output 13.08.2014

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM