Kumar Kumar - 4 months ago 14
Node.js Question

How to get local timezone in ejs?

I am using

ejs template
and my server have
UTC time
format. I need to convert my timezone into local timezone on user side.

When i use this
<% new Date() %>
this date show server time zone.


You can send your timezoneoffset client side to server and after that when you render your pagefrom server to client using ejs that time send one more parameter timezoneoffset and using this you can convert your time into local time. timeZoneOffset and serverDate is come from server and TIMEOFFSET is local variable. serverDate is in UTC format.

<% var TIMEOFFSET = timeZoneOffset;
    var dateForShow = serverDate;
    dateForShow.setMinutes(dateForShow.getMinutes() + TIMEOFFSET); %>