哪个PHP函数可以返回当前日期/时间?
当前回答
你可以:
$now = strtotime(date('Y-m-d H:i:s')); // = Now
完整的格式选项请参见文档:https://www.php.net/manual/en/function.date.php
其他回答
你可以使用下面的代码:
<?php
$currentDateTime = date('Y-m-d H:i:s');
echo $currentDateTime;
?>
如果你想获得日期,如12-3-2016,分开每一天,月和年的值,然后复制粘贴以下代码:
$day = date("d");
$month = date("m");
$year = date("y");
print "date" . $day . "-" . $month . "-" . $year;
参考:这里有一个链接
由于使用夏令时,这比简单地在时间戳中添加或减去一天或一个月中的秒数更可靠。
PHP代码
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
$today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (the MySQL DATETIME format)
PHP的date函数可以完成这项工作。
日期()
描述:
string date(string $format [, int $timestamp = time()])
返回根据给定格式字符串使用给定整数时间戳格式化的字符串,如果没有给出时间戳则返回当前时间。
例子:
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
$today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (the MySQL DATETIME format)
您可以使用$_SERVER['REQUEST_TIME']变量(自PHP 5.1.0起可用)或time()函数来获取当前的Unix时间戳。
推荐文章
- 如何实现一个好的脏话过滤器?
- PHP中的三个点(…)是什么意思?
- Guzzlehttp -如何从guzzle6得到响应的正文?
- 移动一个文件到服务器上的另一个文件夹
- Laravel中使用雄辩的ORM进行批量插入
- PHP 5.4调用时引用传递-容易修复可用吗?
- 格式化字节到千字节,兆字节,千兆字节
- 如何在PowerShell格式化日期时间
- 如何在PHP中获得变量名作为字符串?
- 在c#中解析字符串为日期时间
- 用“+”(数组联合运算符)合并两个数组如何工作?
- Laravel PHP命令未找到
- 如何修复从源代码安装PHP时未发现xml2-config的错误?
- 如何在Python中获取UTC时间?
- 在PHP中对动态变量名使用大括号