PHP日期字符串格式 [英] PHP Date String Format

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

问题描述

我有一个字符串mm-dd-yyyy,我从一个窗体,我想将其存储在数据类型DATE(yyyy-mm-dd)的数据库。

I have a string mm-dd-yyyy which i get from a form, which i want to store it in the database of the data-type DATE (yyyy-mm-dd).

如何格式化字符串并将其保存在数据库中?

How do i format the string and save it in the database ?

推荐答案

$new_format = date("Y-m-d", strtotime('04-28-2012'));

$date = new DateTime('04-28-2012');
$new_format = $date->format('Y-m-d');

或PHP 5.5 +

or in PHP 5.5+

$new_format = (new DateTime('04-28-2012'))->format('Y-m-d');

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

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