Thought I understood how to convert a time stored in our DB to the users local time but seems I do not. When I save the kick off time into my postresql database (On Heroku) it is supplied as 2018-11-14 19:45:00
, I save it as a TIMESTAMP. At the time i save it should I use moment?
Running Heroku logs I have noticed that the server time is 2018-11-14T19:45:00.200076+00:00
, which is UTC ?
Using moment JS in my node app I am carrying out the following
fixture.kick_off = 2018-11-14 19:45:00.000000
<%= moment(fixture.kick_off).local().format('HH:mm A') %>
I have had a user from Denmark state that this is showing as 19:45 pm, where as i wanted it to show 20:45 PM as per the time difference
Have I misunderstood something here (very likely)
Thanks
Update
I am now using the below as per Matt's answer
<%= moment.utc(fixture.kick_off).local().format('HH:mm A') %>
Following on from Matt's comment around checking the typeof fixture.kick_off, it was returning object
, have now updated my code to be
<% var kick_off = fixture.kick_off.toString() %>
<%= moment.utc(kick_off).local().format('HH:mm') %>
Which returns the following in the console
Deprecation warning: value provided is not in a recognized RFC2822 or ISO
format. moment construction falls back to js Date(), which is not reliable
across all browsers and versions. Non RFC2822/ISO date formats are discouraged
and will be removed in an upcoming major release. Please refer to
http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: Thu
Nov 15 2018 19:00:00 GMT+0000 (Greenwich Mean Time), _f: undefined, _strict:
undefined, _locale: [object Object]
Error