3

I created a time field by the Q&A Magento 2 - How to add the DateTime UI Component, and I also set the store TimeZone is "Asia/Shanghai". But when I click the "Go Today", it always show the time of UTC timezone. How to fix it?

datetime UI Componet

2

The timezone is right. The origin of the problem is the wrong timeFormat in the answer of Magento 2 - How to add the DateTime UI Component, We need change hh:mm:ss to HH:mm:ss in the UI Componet, otherwise 03:00:00 PMand 03:00:00 AM will became the same time, lack 12 hours and you can not save the time of PM in DB table.


Below is the original answer from Magento 2 - How to add the DateTime UI Component, we need change <item name="timeFormat" xsi:type="string">hh:mm:ss</item> to <item name="timeFormat" xsi:type="string">HH:mm:ss</item>.

<field name="start_date">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">string</item>
            <item name="label" xsi:type="string" translate="true">Go Live Start Date</item>
            <item name="formElement" xsi:type="string">date</item>
            <item name="source" xsi:type="string">page</item>
            <item name="sortOrder" xsi:type="number">21</item>
            <item name="dataScope" xsi:type="string">start_date</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
            <item name="options" xsi:type="array">
                <item name="dateFormat" xsi:type="string">yyyy-MM-dd</item>
                <item name="timeFormat" xsi:type="string">hh:mm:ss</item>
                <item name="showsTime" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>
  • I want to store that date which is selected from ui_form.When I select any date from UI form and click on Save then magento will convert that date in UTC format by default. So I am not getting selected date but I got date in UTC format.I want to get that date which selected from ui form. Anyone knows how to solve? – Emipro Technologies Pvt. Ltd. May 24 '18 at 12:41
  • @EmiproTechnologiesPvt.Ltd. Try set the timezone in Magento admin, the default timezone is UTC. – Key Shang May 25 '18 at 1:30
  • @EmiproTechnologiesPvt.Ltd. Have you found the answer? I have same question? – Rutvee Sojitra Aug 21 '18 at 9:07
  • @EmiproTechnologiesPvt.Ltd. i also facing same problem have you found something to display only time & save same format to database? – Chirag Patel Nov 15 '18 at 13:41
  • @RutveeSojitra i also facing same problem have you found something to display only time & save same format to database? – Chirag Patel Nov 15 '18 at 13:41

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.