Kumar Kumar - 1 year ago 158
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.

Answer Source

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); %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download