有没有办法在 PHP 中更改日期格式?

phpserver side programmingprogramming更新于 2025/6/25 18:37:17

可以,在 PHP 中使用 date() 和 strtotime() 函数更改日期格式。假设以下是我们的日期减去

$dateValue = "2020-09-19";

使用 strtotime() 方法更改日期格式 −

$modifiedDate= date("d-m-Y", strtotime($dateValue));  

示例

<!DOCTYPE html>
<html>
<body>
<?php
   $dateValue = "2020-09-19";
   echo "The original date format is=",$dateValue,"<br>";
   $modifiedDate= date("d-m-Y", strtotime($dateValue));  
   echo "The changed date format is= ".$modifiedDate;  
?>
</body>
</html>

输出

这将产生以下输出 −

The original date format is=2020-09-19
The changed date format is= 19-09-2020

相关文章