Momentjs utc() working differently on local (Mac) and server (Ubuntu)









up vote
0
down vote

favorite












Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.



When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only



using moment@2.22.2



On Ubuntu 16.04.4 LTS



> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'


On Mac OsX 10.13.2



> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'









share|improve this question























  • Should use the format argument of moment(input, format) when you use a non standard ISO date string
    – charlietfl
    Nov 10 at 17:06











  • thnk u but unfortunately, format option doesn't solve this problem
    – dima
    Nov 10 at 17:40














up vote
0
down vote

favorite












Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.



When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only



using moment@2.22.2



On Ubuntu 16.04.4 LTS



> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'


On Mac OsX 10.13.2



> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'









share|improve this question























  • Should use the format argument of moment(input, format) when you use a non standard ISO date string
    – charlietfl
    Nov 10 at 17:06











  • thnk u but unfortunately, format option doesn't solve this problem
    – dima
    Nov 10 at 17:40












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.



When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only



using moment@2.22.2



On Ubuntu 16.04.4 LTS



> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'


On Mac OsX 10.13.2



> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'









share|improve this question















Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.



When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only



using moment@2.22.2



On Ubuntu 16.04.4 LTS



> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'


On Mac OsX 10.13.2



> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'






javascript momentjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 18:11

























asked Nov 10 at 16:57









dima

55557




55557











  • Should use the format argument of moment(input, format) when you use a non standard ISO date string
    – charlietfl
    Nov 10 at 17:06











  • thnk u but unfortunately, format option doesn't solve this problem
    – dima
    Nov 10 at 17:40
















  • Should use the format argument of moment(input, format) when you use a non standard ISO date string
    – charlietfl
    Nov 10 at 17:06











  • thnk u but unfortunately, format option doesn't solve this problem
    – dima
    Nov 10 at 17:40















Should use the format argument of moment(input, format) when you use a non standard ISO date string
– charlietfl
Nov 10 at 17:06





Should use the format argument of moment(input, format) when you use a non standard ISO date string
– charlietfl
Nov 10 at 17:06













thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40




thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc() translates it to UTC time. So you get different results.



If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)






share|improve this answer



























    up vote
    0
    down vote













    Try to provide the format in which data string is



    console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())





    share|improve this answer




















    • Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
      – dima
      Nov 10 at 17:38










    • Which platform it shown different behaviour
      – front_end_dev
      Nov 10 at 17:42










    • ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
      – dima
      Nov 10 at 17:57











    • @dima Didn't have ubuntu unable to debug this.
      – front_end_dev
      Nov 10 at 18:00










    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',
    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%2f53241248%2fmomentjs-utc-working-differently-on-local-mac-and-server-ubuntu%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc() translates it to UTC time. So you get different results.



    If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)






    share|improve this answer
























      up vote
      1
      down vote



      accepted










      Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc() translates it to UTC time. So you get different results.



      If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)






      share|improve this answer






















        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc() translates it to UTC time. So you get different results.



        If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)






        share|improve this answer












        Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc() translates it to UTC time. So you get different results.



        If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 15:03









        snickersnack

        1463




        1463






















            up vote
            0
            down vote













            Try to provide the format in which data string is



            console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())





            share|improve this answer




















            • Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
              – dima
              Nov 10 at 17:38










            • Which platform it shown different behaviour
              – front_end_dev
              Nov 10 at 17:42










            • ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
              – dima
              Nov 10 at 17:57











            • @dima Didn't have ubuntu unable to debug this.
              – front_end_dev
              Nov 10 at 18:00














            up vote
            0
            down vote













            Try to provide the format in which data string is



            console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())





            share|improve this answer




















            • Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
              – dima
              Nov 10 at 17:38










            • Which platform it shown different behaviour
              – front_end_dev
              Nov 10 at 17:42










            • ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
              – dima
              Nov 10 at 17:57











            • @dima Didn't have ubuntu unable to debug this.
              – front_end_dev
              Nov 10 at 18:00












            up vote
            0
            down vote










            up vote
            0
            down vote









            Try to provide the format in which data string is



            console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())





            share|improve this answer












            Try to provide the format in which data string is



            console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 17:16









            front_end_dev

            1,3101411




            1,3101411











            • Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
              – dima
              Nov 10 at 17:38










            • Which platform it shown different behaviour
              – front_end_dev
              Nov 10 at 17:42










            • ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
              – dima
              Nov 10 at 17:57











            • @dima Didn't have ubuntu unable to debug this.
              – front_end_dev
              Nov 10 at 18:00
















            • Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
              – dima
              Nov 10 at 17:38










            • Which platform it shown different behaviour
              – front_end_dev
              Nov 10 at 17:42










            • ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
              – dima
              Nov 10 at 17:57











            • @dima Didn't have ubuntu unable to debug this.
              – front_end_dev
              Nov 10 at 18:00















            Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
            – dima
            Nov 10 at 17:38




            Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
            – dima
            Nov 10 at 17:38












            Which platform it shown different behaviour
            – front_end_dev
            Nov 10 at 17:42




            Which platform it shown different behaviour
            – front_end_dev
            Nov 10 at 17:42












            ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
            – dima
            Nov 10 at 17:57





            ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
            – dima
            Nov 10 at 17:57













            @dima Didn't have ubuntu unable to debug this.
            – front_end_dev
            Nov 10 at 18:00




            @dima Didn't have ubuntu unable to debug this.
            – front_end_dev
            Nov 10 at 18:00

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241248%2fmomentjs-utc-working-differently-on-local-mac-and-server-ubuntu%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?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto