PHP在POST之前重新格式化日期 [英] PHP reformat date before POST

查看:227
本文介绍了PHP在POST之前重新格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从PHP表单发布日期时,我必须将其输入为YYYY-MM-DD才能被接受.有什么办法可以重新设置发布日期,以便人们可以将其输入为DD-MM-YYYY?

while posting a date from a PHP form, I must enter it as YYYY-MM-DD to be accepted. is there a way I can reformat the date as it POSTS so people can enter it as DD-MM-YYYY?

. date("M d, Y", strtotime($_POST['dob']));

..还是什么?

推荐答案

运行正常

<?php
echo date("M d, Y", strtotime('12-06-1982'));
?>

输出

Jun 12, 1982

示例更新

HTML

<form action="date.php" method="post">
<input type="text" name="dob"/> <input type="submit" name="submitDate" value="submit"/>
</form>

date.php

<?php
if ($_POST['submitDate']){
echo date("M d, Y", strtotime($_POST['dob']));
}
?>

这将以您想要的格式返回日期.简单!

This will return the date in that format that you want. Simple!

这篇关于PHP在POST之前重新格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆