How to format a datetime column using client timezone

How to format a datetime column using client timezone

jstuardojstuardo Posts: 91Questions: 37Answers: 0
edited October 2020 in Free community support

Hello, I have a database table that has a datetime column that stores date and time using UTC. I need to show that date and time using client tomezone.

If I use render: $.fn.dataTable.render.moment('', 'DD/MM/YYYY HH:mm:ss') datetime appears in UTC timezone.

I cannot do conversion in server side, because server has in a different timezone than clients.

Any help, please?

Thanks

Jaime

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    Take a look at this please: https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript

    Look for moment-timezone

    You need to change the date-time value BEFORE it is being rendered using $.fn.dataTable.render.moment.

  • jstuardojstuardo Posts: 91Questions: 37Answers: 0
    edited October 2020

    Thanks, but I could not use $.fn.dataTable.render.moment.

    Finally I have used:

                        render: function (data, type, row, meta) {
                            return moment.utc(data).local().format('DD/MM/YYYY HH:mm:ss');
                        }
    
  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited October 2020

    Glad you got it working! Many roads lead to Rome!
    And thanks for posting your solution. I do date rendering server side and it is CET (central european time) only which won't work if we expand beyond that time zone (which is pretty big though ...).

This discussion has been closed.