如何使用getdate()正确地将日期存储在变量中

时间:2010-08-04 22:58:35

标签: php

我试图使用getdate()将日期存储在变量中。我做错了什么?

$today = getdate();

echo "the date today is ".$today;

输出:今天的日期是数组

3 个答案:

答案 0 :(得分:0)

getdate()返回一个数组。要回显秒,您可能想尝试这个:

$getdate = getdate();

echo "there are ".$getdate['seconds']." on the minute";

查看所有密钥及其返回的内容here.

答案 1 :(得分:0)

getdate()返回一个数组,因此您可能需要执行类似

的操作
echo 'The date today is '. $today['year'].'-'.$today['mon'].'-'.$today['mday'];

我更喜欢使用date()

echo 'The date today is '. date('Y-m-d');

答案 2 :(得分:0)

那是因为getdate()返回一个数组。试试

print_r($today)

亲眼看看。 this也应该帮助你。

相关问题