为什么我在结果中得到一个空白页而不是今天的日期遵循PHP代码?

时间:2023-01-18 23:25:36

I've following small code snippet to display today's date and value of one variable but I'm getting the blank white page in result. Why so?

我已经按照小代码片段来显示今天的日期和一个变量的值,但我得到的结果是空白页。为什么这样?

My code is as below:

我的代码如下:

<?php
  $form_data['trans_date'] = '12-11-2014';// Date format is MM-DD-YYYY i.e. 11th December 2014
  $newTransDate = DateTime::createFromFormat('!m-d-Y', $form_data['trans_date']);
  $today_date = new DateTime('today');
  echo "Today Date ".$today_date; die;//Here I want to print today's date
  $form_data['trans_date'] = '12-11-2014';
  $newTransDate = DateTime::createFromFormat('!m-d-Y', $form_data['trans_date']);
  $today_date = new DateTime('today');
  echo "Today Date ".$newTransDate."<br>"; die;//Here I wan tot print today's date
  echo "New Trans Date ".$newTransDate; die;//Here I wan tot print value of var $newTransDate
  ?>

Thanks in advance.

提前致谢。

1 个解决方案

#1


0  

When you are using PHP's DateTime, while outputting you need to define the output format.

当您使用PHP的DateTime时,在输出时您需要定义输出格式。

// Create a new DateTime object
$now = new DateTime();

// Output
echo $now->format('Y-m-d H:i:s');

#1


0  

When you are using PHP's DateTime, while outputting you need to define the output format.

当您使用PHP的DateTime时,在输出时您需要定义输出格式。

// Create a new DateTime object
$now = new DateTime();

// Output
echo $now->format('Y-m-d H:i:s');