Yii - ¿Qué métodos usar para procesar este cambio de fecha?

I'm not sure where to make this. Here's part of my config file:

'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'myApp',
        'defaultController' => 'event/index', //events as default
        'language'=>'pt',
        'timeZone'=>'Europe/Lisbon',
        'localeDataPath'=>dirname(__FILE__).'/../data/i18n',

   'components'=>array(
            'format' => array(
                    'datetimeFormat' => 'dd/mm/yyyy hh:mm',
                    'dateFormat' => 'dd/mm/yyyy',
                    'timeFormat' => 'hh:mm',
            ), 

So: I'm retrieving the date as a string like this:

'2010-11-02'

So I need to convert this string to: 02-11-2010 .

He intentado esto:

Yii::app()->format->formatDate($data); 

Yo obtengo:

"A non well formed numeric value encountered"

¿Por qué?

:s

Update: Used: yii::app()->dateFormatter->format('dd', $data); //to return the day; Used: yii::app()->dateFormatter->format('MMMM', $data); //to return the month;

trabajado.

preguntado el 04 de julio de 12 a las 00:07

Has mirado CDateFormatter? -

I now have. thanks. I've change the config file, and I was excepting the date to change from yyyy-mm-dd a dd/mm/yyyy . No luck. the data coming from the db still preserves their stored format. :( -

1 Respuestas

We have in config:

 'components' => array(
       'format' => array(
            'datetimeFormat' => 'm/d/Y h:i A',
            'dateFormat' => 'm/d/Y',
            'timeFormat' => 'h:i A',
        ),

and we use like:

y puedes usar Yii::app()->format formatear

Respondido 04 Jul 12, 08:07

So, when you receive data from the database on yyyy/mm/dd you use your format settings to change it. But on this case, I would have the need for two different formats. One for the forms other for presentation views as stated on original question. So I guess I can't follow that path. Anyway, is format an alternative method of CDateFormatter ? Gracias. - MEM

format is an application component, and it's a wrapper to CDateFormatter. The format method takes format parameters, it's up to you what parameters you give. - Pentium10

Ok. I've tried that. A date is coming from my database as yyyy-mm-dd and I wish to convert it as dd/mm/yyyy so I've made the appropriate changed on config. However, the date doesn't get formated. It preserves the mysql returned format. Shouldn't that change automatically ? - MEM

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.