Moment JS and convert to local time of user










0















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









share|improve this question




























    0















    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









    share|improve this question


























      0












      0








      0








      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









      share|improve this question
















      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






      node.js timezone momentjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 23:39







      Richlewis

















      asked Nov 14 '18 at 22:08









      RichlewisRichlewis

      7,6662471171




      7,6662471171






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Assuming the time stored in your database based on UTC, you simply forgot to tell moment that. Use moment.utc(input) instead of moment(input)



          moment.utc(fixture.kick_off).local().format('HH:mm A')





          share|improve this answer























          • I knew you would come to my rescue Matt :-) I have just finished reading this too (typical i found it after asking the question) stackoverflow.com/questions/32540667/… thank you for taking the time to answer, just trying this out now

            – Richlewis
            Nov 14 '18 at 22:22











          • hmm, still not working apparently, maybe my issue stems from elsewhere then, Ill investigate and update my question

            – Richlewis
            Nov 14 '18 at 22:33











          • Looking at your edit, the question is a but murky now. If the UTC time is 22:37, then the time in Denmark (UTC+1 on that date) would be 23:37, but you're asking for 20:45? Can you please clean up your question to be consistent?

            – Matt Johnson
            Nov 14 '18 at 22:44











          • apologies, I have cleaned it up now, the Heroku server time is the same as here in the UK. If this question is still murky, happy to delete it and start again

            – Richlewis
            Nov 14 '18 at 22:48











          • Keep in mind that the UK isn't always aligned to UTC. It does UTC+1 for BST. But I don't think that's the source of your problem. Probably multiple things compounding here. I recommend doing some debugging and make sure that fixture.kick_off is really a string with a value like you showed here (you're missing quotation marks though - maybe you don't have a string but something else, like a Date object?)

            – Matt Johnson
            Nov 14 '18 at 23:05










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309464%2fmoment-js-and-convert-to-local-time-of-user%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Assuming the time stored in your database based on UTC, you simply forgot to tell moment that. Use moment.utc(input) instead of moment(input)



          moment.utc(fixture.kick_off).local().format('HH:mm A')





          share|improve this answer























          • I knew you would come to my rescue Matt :-) I have just finished reading this too (typical i found it after asking the question) stackoverflow.com/questions/32540667/… thank you for taking the time to answer, just trying this out now

            – Richlewis
            Nov 14 '18 at 22:22











          • hmm, still not working apparently, maybe my issue stems from elsewhere then, Ill investigate and update my question

            – Richlewis
            Nov 14 '18 at 22:33











          • Looking at your edit, the question is a but murky now. If the UTC time is 22:37, then the time in Denmark (UTC+1 on that date) would be 23:37, but you're asking for 20:45? Can you please clean up your question to be consistent?

            – Matt Johnson
            Nov 14 '18 at 22:44











          • apologies, I have cleaned it up now, the Heroku server time is the same as here in the UK. If this question is still murky, happy to delete it and start again

            – Richlewis
            Nov 14 '18 at 22:48











          • Keep in mind that the UK isn't always aligned to UTC. It does UTC+1 for BST. But I don't think that's the source of your problem. Probably multiple things compounding here. I recommend doing some debugging and make sure that fixture.kick_off is really a string with a value like you showed here (you're missing quotation marks though - maybe you don't have a string but something else, like a Date object?)

            – Matt Johnson
            Nov 14 '18 at 23:05















          0














          Assuming the time stored in your database based on UTC, you simply forgot to tell moment that. Use moment.utc(input) instead of moment(input)



          moment.utc(fixture.kick_off).local().format('HH:mm A')





          share|improve this answer























          • I knew you would come to my rescue Matt :-) I have just finished reading this too (typical i found it after asking the question) stackoverflow.com/questions/32540667/… thank you for taking the time to answer, just trying this out now

            – Richlewis
            Nov 14 '18 at 22:22











          • hmm, still not working apparently, maybe my issue stems from elsewhere then, Ill investigate and update my question

            – Richlewis
            Nov 14 '18 at 22:33











          • Looking at your edit, the question is a but murky now. If the UTC time is 22:37, then the time in Denmark (UTC+1 on that date) would be 23:37, but you're asking for 20:45? Can you please clean up your question to be consistent?

            – Matt Johnson
            Nov 14 '18 at 22:44











          • apologies, I have cleaned it up now, the Heroku server time is the same as here in the UK. If this question is still murky, happy to delete it and start again

            – Richlewis
            Nov 14 '18 at 22:48











          • Keep in mind that the UK isn't always aligned to UTC. It does UTC+1 for BST. But I don't think that's the source of your problem. Probably multiple things compounding here. I recommend doing some debugging and make sure that fixture.kick_off is really a string with a value like you showed here (you're missing quotation marks though - maybe you don't have a string but something else, like a Date object?)

            – Matt Johnson
            Nov 14 '18 at 23:05













          0












          0








          0







          Assuming the time stored in your database based on UTC, you simply forgot to tell moment that. Use moment.utc(input) instead of moment(input)



          moment.utc(fixture.kick_off).local().format('HH:mm A')





          share|improve this answer













          Assuming the time stored in your database based on UTC, you simply forgot to tell moment that. Use moment.utc(input) instead of moment(input)



          moment.utc(fixture.kick_off).local().format('HH:mm A')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 22:20









          Matt JohnsonMatt Johnson

          139k42282403




          139k42282403












          • I knew you would come to my rescue Matt :-) I have just finished reading this too (typical i found it after asking the question) stackoverflow.com/questions/32540667/… thank you for taking the time to answer, just trying this out now

            – Richlewis
            Nov 14 '18 at 22:22











          • hmm, still not working apparently, maybe my issue stems from elsewhere then, Ill investigate and update my question

            – Richlewis
            Nov 14 '18 at 22:33











          • Looking at your edit, the question is a but murky now. If the UTC time is 22:37, then the time in Denmark (UTC+1 on that date) would be 23:37, but you're asking for 20:45? Can you please clean up your question to be consistent?

            – Matt Johnson
            Nov 14 '18 at 22:44











          • apologies, I have cleaned it up now, the Heroku server time is the same as here in the UK. If this question is still murky, happy to delete it and start again

            – Richlewis
            Nov 14 '18 at 22:48











          • Keep in mind that the UK isn't always aligned to UTC. It does UTC+1 for BST. But I don't think that's the source of your problem. Probably multiple things compounding here. I recommend doing some debugging and make sure that fixture.kick_off is really a string with a value like you showed here (you're missing quotation marks though - maybe you don't have a string but something else, like a Date object?)

            – Matt Johnson
            Nov 14 '18 at 23:05

















          • I knew you would come to my rescue Matt :-) I have just finished reading this too (typical i found it after asking the question) stackoverflow.com/questions/32540667/… thank you for taking the time to answer, just trying this out now

            – Richlewis
            Nov 14 '18 at 22:22











          • hmm, still not working apparently, maybe my issue stems from elsewhere then, Ill investigate and update my question

            – Richlewis
            Nov 14 '18 at 22:33











          • Looking at your edit, the question is a but murky now. If the UTC time is 22:37, then the time in Denmark (UTC+1 on that date) would be 23:37, but you're asking for 20:45? Can you please clean up your question to be consistent?

            – Matt Johnson
            Nov 14 '18 at 22:44











          • apologies, I have cleaned it up now, the Heroku server time is the same as here in the UK. If this question is still murky, happy to delete it and start again

            – Richlewis
            Nov 14 '18 at 22:48











          • Keep in mind that the UK isn't always aligned to UTC. It does UTC+1 for BST. But I don't think that's the source of your problem. Probably multiple things compounding here. I recommend doing some debugging and make sure that fixture.kick_off is really a string with a value like you showed here (you're missing quotation marks though - maybe you don't have a string but something else, like a Date object?)

            – Matt Johnson
            Nov 14 '18 at 23:05
















          I knew you would come to my rescue Matt :-) I have just finished reading this too (typical i found it after asking the question) stackoverflow.com/questions/32540667/… thank you for taking the time to answer, just trying this out now

          – Richlewis
          Nov 14 '18 at 22:22





          I knew you would come to my rescue Matt :-) I have just finished reading this too (typical i found it after asking the question) stackoverflow.com/questions/32540667/… thank you for taking the time to answer, just trying this out now

          – Richlewis
          Nov 14 '18 at 22:22













          hmm, still not working apparently, maybe my issue stems from elsewhere then, Ill investigate and update my question

          – Richlewis
          Nov 14 '18 at 22:33





          hmm, still not working apparently, maybe my issue stems from elsewhere then, Ill investigate and update my question

          – Richlewis
          Nov 14 '18 at 22:33













          Looking at your edit, the question is a but murky now. If the UTC time is 22:37, then the time in Denmark (UTC+1 on that date) would be 23:37, but you're asking for 20:45? Can you please clean up your question to be consistent?

          – Matt Johnson
          Nov 14 '18 at 22:44





          Looking at your edit, the question is a but murky now. If the UTC time is 22:37, then the time in Denmark (UTC+1 on that date) would be 23:37, but you're asking for 20:45? Can you please clean up your question to be consistent?

          – Matt Johnson
          Nov 14 '18 at 22:44













          apologies, I have cleaned it up now, the Heroku server time is the same as here in the UK. If this question is still murky, happy to delete it and start again

          – Richlewis
          Nov 14 '18 at 22:48





          apologies, I have cleaned it up now, the Heroku server time is the same as here in the UK. If this question is still murky, happy to delete it and start again

          – Richlewis
          Nov 14 '18 at 22:48













          Keep in mind that the UK isn't always aligned to UTC. It does UTC+1 for BST. But I don't think that's the source of your problem. Probably multiple things compounding here. I recommend doing some debugging and make sure that fixture.kick_off is really a string with a value like you showed here (you're missing quotation marks though - maybe you don't have a string but something else, like a Date object?)

          – Matt Johnson
          Nov 14 '18 at 23:05





          Keep in mind that the UK isn't always aligned to UTC. It does UTC+1 for BST. But I don't think that's the source of your problem. Probably multiple things compounding here. I recommend doing some debugging and make sure that fixture.kick_off is really a string with a value like you showed here (you're missing quotation marks though - maybe you don't have a string but something else, like a Date object?)

          – Matt Johnson
          Nov 14 '18 at 23:05



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309464%2fmoment-js-and-convert-to-local-time-of-user%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto