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?
2 Answers
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 PM
and 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? Commented May 24, 2018 at 12:41
-
@EmiproTechnologiesPvt.Ltd. Try set the timezone in Magento admin, the default timezone is UTC. Commented May 25, 2018 at 1:30
-
@EmiproTechnologiesPvt.Ltd. Have you found the answer? I have same question? Commented Aug 21, 2018 at 9:07
-
@EmiproTechnologiesPvt.Ltd. i also facing same problem have you found something to display only time & save same format to database? Commented Nov 15, 2018 at 13:41
-
@RutveeSojitra i also facing same problem have you found something to display only time & save same format to database? Commented Nov 15, 2018 at 13:41
You have to use the store time zone as well otherwise when you select the time its auto-convert to the UTC time zone
<item name="storeTimeZone" xsi:type="string">string</item>