简体   繁体   中英

Error when using JDATE in joomla 2.5

I have a sample code:

<?php 
    echo JHTML::_('date', '2012-08-03 03:02:44' , '%d/%m/%Y - %H:%M');
?>

But result is: %03/%08/%2012 - %10:%Aug => How to fix it ?

try this

<?php 
    echo JHTML::_('date', '2012-08-03 03:02:44' , 'd/m/Y - H:i');
?>

It's easier to let Joomla control the display format as it will support multiple languages for example.

 $date= JHtml::date($input= 'now', JText::_('DATE_FORMAT_LC1'), false); 

This will display the date time (now) in the format LC1 as defined in Joomla's language files with the websites date time offset by the timezone defined in the websites configuration file.

LC1 in en-GB will output -> Saturday, 10 November 2012

LC2 in en-GB will output -> Saturday, 10 November 2012 12:09

LC3 in en-GB will output -> 10 November 2012

LC4 in en-GB will output -> 2012-11-10

JS1 in en-GB will output -> 12-11-10

You can create your own formats by adding or editing their corresponding language strings. Also if you want the date time to be offset by the current users setting change the last value to true.

More Examples

// Server Timezone: "New York" (-0500 GMT)

// User Timeszone: "Los Angeles" (-0800 GMT)

jimport( 'joomla.html.html' );

$sqlGmtTimestamp = "2012-03-01 20:00:00"

echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a'); // Fri March 1, 2012 12:00 pm

echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a', true); // Fri March 1, 2012 12:00 pm

echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a', false); // Fri March 1, 2012 3:00 pm

References:

API16:JHtml/date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM