I'm using Display Suite, which takes over the node's created timestamp and turns it into a field named post_date. Therefore, I overrode the field.tpl.php file and named it field--post-date.tpl.php, and added the time element to the markup:
<div class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php if (!$label_hidden): ?>
<div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>: </div>
<?php endif; ?>
<div class="field-items"<?php print $content_attributes; ?>>
<?php foreach ($items as $delta => $item): ?>
<div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><time datetime="<?php print $datetime; ?>"><?php print render($item); ?></time></div>
<?php endforeach; ?>
</div>
</div>
To get the $datetime variable, I added the following code to theme_preprocess_field():
function mytheme_preprocess_field(&$vars) {
// check for Display Suite fields.
if ($vars['element']['#field_type'] != 'ds') {
return;
}
switch ($vars['element']['#field_name']) {
case 'post_date':
if ($vars['element']['#entity_type'] != 'node') {
break;
}
$node = $vars['element']['#object'];
$vars['datetime'] = date_iso8601($node->created);
break;
}
}
I'm just handling nodes, and a node always has one created time. The loop in the tpl file can probably be removed, since there will always be one value.