Cakephp和DateTimePicker格式 [英] Cakephp and DateTimePicker format

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

问题描述

我在显示日期时遇到格式问题。

I have problem with the format when displaying date.

我使用jquery DateTimePicker( http://www.malot.fr/bootstrap-datetimepicker/ )。

I use jquery DateTimePicker (http://www.malot.fr/bootstrap-datetimepicker/).

在我有

<div class="input-append date" id="dp">
    <?php
        echo $form->input('date',array('type' => 'text','div' => false, 'label' => 'Date'));
    ?>
    <span class="add-on"><i class="icon-remove"></i></span>
    <span class="add-on"><i class="icon-calendar"></i></span>
</div>

包含日期的表单数据,而脚本为

with form data which contains date, while script is

<script>
    $('#dp').datetimepicker({
    format: 'd MM yyyy',
        autoclose: 1,
        forceParse: 1,
        todayBtn: 1,
        minView: 2
    });
</script>

表单日期格式为yyyy-mm-dd,并显示在日期字段

Form date has the format "yyyy-mm-dd" and it is displayed in the date field "date" in that format, ie "2013-03-25" instead of "25 March 2013" regardless of the format defined in the script.

在其他情况下,您可以使用2013-03-25而不是2013年3月25日当用户使用选择器拾取日期时,根据脚本中的定义('d MM yyyy'),日期字段中的显示格式正确。

In the other case, when the user picks up the date by using picker, displayed format in the date field is correct, according to definition in the script ('d MM yyyy').

第二问题产生于预期提交的日期格式应为yyyy-mm-dd,以上代码以d MM yyyy格式生成日期。

Second problem arises from the fact that expected submitted date format should be "yyyy-mm-dd", and above code produces date in the format "d MM yyyy".

I尝试镜像字段,

$this->request->data['OSSS']['date_display'] = $this->request->data['OSSS']['date'];
echo $form->input('date_display',array('type' => 'text','div' => false, 'label' => 'Date'));

linkField = 'OSSSdate';
linkFormat = 'yyyy-mm-dd';

然后提交的日期格式正确,但仍然是表单日期格式的问题,显示格式。

and then submitted date is in the correct format, but still remains the problem with the form date format and display format.

任何人都有想法如何在datetimepicker中显示时格式化日期。

Anybody has the idea how to format form date when displaying in the datetimepicker?

推荐答案

我不知道你是否有你的工作。但这对我有用...

I'm not sure if you got yours to work. But this works for me...

<div class="control-group">
        <div class="input-append date controls" id="dp">
            <?php echo $this->Form->input('created',array('type' => 'text','div' => false, 'label' => false, 'wrapInput' => false));?>

        <span class="add-on"><i class="icon-calendar"></i></span>
    </div>
</div>

,然后

$('#dp').datetimepicker({
    format: 'yyyy/MM/dd hh:mm:ss',  //format: 'yyyy-MM-dd hh:mm:ss' either one works     
    language: 'en',
    pick12HourFormat: true
  });

这适用于我,我的created字段是一个datetime字段。 MySQL 5.5

This works for me, my 'created' field is a datetime field. MySQL 5.5

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

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