我有一个在线日期表格。当人们在网站上选择日期时,它会读取dd-mm-yyyy,但是当我收到电子邮件时,它会显示为yyyy-mm-dd。
我需要使用哪些代码将日期更改为mm-dd-yyyy
HTML CODE:
<form id="easy" name="contact" method="post" action="submit.php" onSubmit="return checkform()">
<div class="input">
<label for="date">Enter your birthday:</label>
<input type="date" id="date" name="date">
</div>
<button type='submit' class="button" id='send_message'>Send</button>
</form>
PHP代码向我发送电子邮件(submit.php):
<?php
error_reporting(0);
$emailAddress = 'MYEMAILS@EMAIL.COM';
require "form/class.phpmailer.php";
$msg='You have been contacted by '.$_POST['name'].'<br /><br />
<table style="padding:0;margin: 0;padding: 3px;width: 100%;border: 1px solid #000000;border-collapse: collapse;border-spacing: 0;">
<tr>
<td style="width:35%;background:#1775ca;color:#FFF;padding:3px;">Field</td>
<td style="width:65%;background:#1775ca;color:#FFF;padding:3px;">Entry</td>
</tr>
<tr>
<td>Date</td><td>'.$_POST['date'].'</td>
</tr>
</table>
<br />
You can contact '.$_POST['name'].' via the email '.$_POST['email'].' <br />
The recorded IP is '.$_SERVER['REMOTE_ADDR'].'';
?>
答案 0 :(得分:0)
<?php
$your_date = "2018-03-24";
list($year, $month, $day) = explode('-', $your_date);
$new_date = sprintf("%s-%s-%s", $day, $month, $year);
echo $new_date;
//Output: 24-03-2018
答案 1 :(得分:0)
用户看到的格式取决于其位置,但返回给您的值始终为&#34; yyyy-mm-dd&#34;。
你可以使用datetime类转换它:
$myDateTime = DateTime::createFromFormat('Y-m-d', $_POST['date']);
$newDateString = $myDateTime->format('m-d-Y');
答案 2 :(得分:0)
您可以使用date()和strtotime()函数创建几乎任何格式的字符串。
改变这个:
<td>Date</td><td>'.$_POST['date'].'</td>
要:
<td>Date</td><td>' . date('m-d-Y', strtotime($_POST['date'])) . '</td>