Convert UTC Time to Local Time for an Array of Data

It would be better to handle it on the SQL side I think.
I’m not sure if there would be an easy way to do this on the server action end.
You can also convert on the client side, but that is not your requirement I assume.

So, in MySQL, there is this function to do convert stored date time values. You can send the local time zone as param to the server action GET/POST… then use that to maybe create a custom query with params.

If you are willing to do this on the client side, you can create a date formatter using moment JS to convert time to local time zone.
So, wherever you bind the date time value, you will use something like time_sent.getLocalTime().

Here is an example of formatter I use to convert date time to Sydney/Australia:
//DMX formatters to get Australian Sydney Timezone DateTime dmx.Formatter('string', 'datetimeNow', function (val) { // var today = new Date(); let today = new Date().toLocaleString("en-US", { timeZone: "Australia/Sydney" }); return moment(new Date(today)).format("YYYY-MM-DDTHH:mm:ss"); });

PS: I am not sure why I use en-US, but it just works, so didn’t dig into it. :sweat_smile:

1 Like