将由jquery datepicker创建的日期转换为标准的mysql dateformat [英] Convert date created by jquery datepicker into a standard mysql dateformat
问题描述
我正在使用以下jquery date&时间选择器在日记页面上。
http://trentrichardson.com/examples/timepicker/#rest_examples
它的快捷方便使用,使日期变得容易阅读,但我遇到的问题是,我不知道如何将它转换为标准的mysql日期格式将其保存到数据库中。
在我选择日期和时间的那一刻,它将添加到定时输入框中,像这样>>
Wed 2013年1月9日01:43 pm
如果我点击提交,它不会保存到数据库。
有没有人知道如何将它转换成php中处理发布的数据并像往常一样保存的格式,因为它驱使我绕过弯路,试图找出一种转换方式? / p>
目前用于jquery部分的代码im是以下内容:
< script type =text / javascript>
$(function(){
$('#timedate')。datetimepicker({
timeFormat:hh:mm tt,
dateFormat:D MM d,yy
});});< / script>
创建一个日期,如:
Wed 2013年1月9日01:43 pm
使用 DateTime :: createFromFormat()
:
$ datetime = DateTime :: createFromFormat(DF d,YH:ia ,'2013年1月9日星期三01:43 pm');
echo $ datetime-> format(Y-m-d H:i:s);
I am using the following jquery date & time picker on a diary page. http://trentrichardson.com/examples/timepicker/#rest_examples
Its quick and easy to use and makes a date thats easy to read but the problem I am having is that im not sure how on earth to convert it to a standard mysql date format to save it to the database.
At the moment when I select a date and time it will add it to the timedate input box as something like this >> Wed January 9, 2013 01:43 pm
If I then hit submit, it doesn't get saved to the database.
Does anyone know how I can convert this into a format in the php that processes the posted data and save it as usual, as its driving me round the bend trying to work out a way of converting it ?.
The code im currently using for the jquery part is the following :
<script type="text/javascript">
$(function(){
$('#timedate').datetimepicker({
timeFormat: "hh:mm tt",
dateFormat: "D MM d, yy"
});});</script>
which creates a date like :
Wed January 9, 2013 01:43 pm
Use DateTime::createFromFormat()
:
$datetime = DateTime::createFromFormat("D F d, Y H:i a", 'Wed January 9, 2013 01:43 pm');
echo $datetime->format("Y-m-d H:i:s");
这篇关于将由jquery datepicker创建的日期转换为标准的mysql dateformat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!