0

I create a plugin in k2, which has a calendar field.
When I choose the time in k2 backend like 2019-03-13 05:00 and save the item, the time auto becomes 2019-03-13 13:00,the date is correct but the time it's always 8 hours later in the field.

<field 
    name="item_gc_endtime"
    type="calendar"
    default=""
    label="choose"
    description=""
    class="input-medium"
    format="%Y-%m-%d %H:%M"
    singleheader="true"
    showtime="true"
    timeformat="24"
    weeknumbers="true"
    filltable="true"
    maxyear="5" 
/>  
  • Can you check your database to see if the time is being stored as you entered it, or if the time is changing before it's stored? – Lodder Mar 13 at 12:37
  • @Lodder after save the time also become 2019-03-13 13:00,now the problem solved,i only use date without time,and use the text field for user to input hour – Anthony Mar 13 at 13:30
0

after save the time also become 2019-03-13 13:00,now the problem solved,i only use date field without time,and use the text field for user to input hour

  • This looks like issue avoidance rather than issue resolution. – mickmackusa Mar 13 at 20:12
0

Joomla! converts dates to UTC for database storage. When pulling from the db for display, use the JHtml::('date',...) function or use the timezone method of the JDate object to convert back to your configured timezone and format date output.

Example 1:

echo JHtml::_('date', $item->created, 'Y-m-d G:i:s A');

Example 2:

$config = JFactory::getConfig();
$tz = new DateTimeZone( $config->get('offset') ); // Joomla!'s configured tz
$date = new JDate( $item->created, 'UTC' );
$date->setTimezone($tz); // apply offset
echo $date->format('Y-m-d G:i:s A', true); // true for local time
  • But surely the creators of K2 are well aware of this technique. While your post appears to be correct in what it explains, I believe the desired solution is merely to correct the timezone settings/config so that K2 works properly "out of the box". See Neil's perspective as commented under the question. Regardless, thank you for crafting an educational and well-presented answer. – mickmackusa Sep 15 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.