Create a simple date formatter to be used in views I am using Views Data Export to create a custom RSS feed that looks like

   My Title
   2012-05-12 22:33:00


Start date is a Date field provided by the Date module.

In order to achieve the date formatting on the second field I have to use the Plain formatter from the Date module to avoid theming tags. Unfortunately plain formatting, gives the raw date as stored in the DB ignoring timezone settings.

I have created a custom field formatter module to tackle this:

/**
* Implements hook_field_formatter_info().
*/
function rss_date_formatter_field_formatter_info() {
    return array(
        'rss' =&gt; array(
          'label' =&gt; t('RSS'),
          'description' =&gt; t('Displays a date as rss.'),
          'field types' =&gt; array('date', 'datestamp', 'datetime'),
    ),  );
}


/**
 * Implements hook_field_formatter_view().
 */
function rss_date_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    $element = array();
    $settings = $display['settings'];
    $formatter = $display['type'];
    foreach ($items as $delta =&gt; $item) {
        $element[$delta] = array('#markup' =&gt; $item['value']);
    }
    return $element;
}


Problem is that no matter what I cannot set $element to return the localtime. $item['value'] contains a string of the date representation as it is stored in the DB (thus UTC). Converting it to a date and then back seems to output nothing. Also if I hardcode a string there, it seems the string is altered but I cannot find from which function this happens (eg. entering 'test' in the #markup returns '1est', like converting the first letter to a valid month (1-12).

Any clues on this? I never thought outputting a date in localtime without theming would be so hard.
You should:


Create a new date format: /admin/config/regional/date-time/formats
Create a new date type that uses the format you just created: admin/config/regional/date-time
Use that date type in view.