【问题标题】:Formatting Date When Sending PHP Form发送 PHP 表单时格式化日期
【发布时间】:2016-10-11 06:12:27
【问题描述】:

这是我的问题。我有一个发送到电子邮件地址的 php 表单。一切都很好,但是日期的格式是 yyyy-mm-dd。我想要日期是,月 DD,YYYY。我需要对我的代码进行哪些更改才能使其正常工作?

<?php
$errors = '';
$myemail = 'email@email.com'; // <-----Put Your email address here.
if (empty($_POST['date']) || empty($_POST['song3']) || 
    empty($_POST['song2']) || empty($_POST['song1'])) {
    $errors .= "\n Error: all fields are required"; 
}

$date = $_POST['date'];  
$song3 = $_POST['song3'];  
$song2 = $_POST['song2'];  
$song1 = $_POST['song1']; 

if (empty($errors)) {
    $to = $myemail;     
    $email_subject = "Hot 3 at 3- $date";   
    $email_body = "Here is today's Hot 3 at 3.\n\n\n" . "3. $song3 \n\n2. $song2 \n\n1. $song1";
    $headers = "From: KLIA-FM\n";
    $headers .= "Reply-To: $email_address";     
    mail($to, $email_subject, $email_body, $headers); // redirect to the 'thank you' page   
    header('Location: thank-you.html'); 
}  
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html> 
<head>  
    <title>Contactform handler</title>
</head>

<body> <!-- This page is displayed only if there is some error -->
    <?php echo nl2br($errors); ?>
</body> 
</html>

【问题讨论】:

标签: php date format


【解决方案1】:

更改自:

 $date = $_POST['date'];

收件人:

$date = date('F d, Y', strtotime($_POST['date']));

这里阅读下面的所有格式:

http://www.w3schools.com/php/func_date_date.asp

【讨论】:

    【解决方案2】:

    试试这个,

    $date = date_create($date);
    $date = date_format($date,"F,d,Y");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多