Link to home
Start Free TrialLog in
Avatar of rivkamak
rivkamakFlag for United States of America

asked on

EJS converting my dat to my timezone

I am trying to set up an express website.

I am getting data from a database in date formats, ie :    2018-11-21T00:00:00.000Z,

My database just default the time to 0000Z, but the day should be 11/21/2018

Whenever I try to display the date,
even as a simple ejs write: <%=item.date %>
it's automatically converting it to my timezone MST, and I'm getting the date as
Tue Nov 20 2018 17:00:00 GMT-0700 (Mountain Standard Time)

How can I set up a standard across my app to keep it as the same day of the month ?
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

You can try using .toDateString() function to convert your date value to string so that it would be even across your app.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString

or else you can use http://momentjs.com/docs/momentjs along with format function to get something like this..
<%= moment(user.date).format( 'MM/DD/YYYY') %>
Avatar of rivkamak

ASKER

I am more concerned that the date that is coming through the database. it should drop the hours and timezone.
and keep the date in the same day of the month.
Will that help?
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial