简体   繁体   English

如何使用PHP获取日期和时间,

[英]How to get date and time with PHP,

I used to get the date and time like this in PHP: 我曾经在PHP中得到这样的日期和时间:

date_default_timezone_set('America/New_York');

$info = getdate();
$date = $info['mday'];
$month = $info['mon'];
$year = $info['year'];
$hour = $info['hours'];
$min = $info['minutes'];
$sec = $info['seconds'];

$time = "D/M/Y= $date/$month/$year H/M/S= $hour:$min:$sec";

Although, now whenever I run it, $time ends up: "0". 虽然,现在每当我运行它时,$ time结束:“0”。

Is there an alternative to this method? 有这种方法的替代方案吗?

Use the date() function to format a date/time. 使用date()函数格式化日期/时间。

echo date('\D/\M/\Y= d/m/Y \H/\M/\S= G:m:s');

To use a literal character ("D" for example), you must escape it. 要使用文字字符(例如“D”),必须将其转义。

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

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