Turning a localized Date to a Timestamp in Firebase











up vote
0
down vote

favorite












I'm new to Firestore and since it doesn't seem like it has a native createdAt/updatedAt as part of a document, I'm creating them when I create the new document. Using a straight up Date() as the value for my initial dictionary that I save to Firestore obviously gives me a localized date/time – UTC -500, for example.



Firestore stores this as November 19, 2018 at 5:14:54 PM UTC-5



Is there a specific date format that Firestore likes in order to save something as a Timestamp and so that I will be able to sort on it later?



I tried using "yyyy-MM-dd HH:mm:ss Z" as the dateFormat from just printing out the value of Date() in a Playground. Would love some help here. Thanks!










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm new to Firestore and since it doesn't seem like it has a native createdAt/updatedAt as part of a document, I'm creating them when I create the new document. Using a straight up Date() as the value for my initial dictionary that I save to Firestore obviously gives me a localized date/time – UTC -500, for example.



    Firestore stores this as November 19, 2018 at 5:14:54 PM UTC-5



    Is there a specific date format that Firestore likes in order to save something as a Timestamp and so that I will be able to sort on it later?



    I tried using "yyyy-MM-dd HH:mm:ss Z" as the dateFormat from just printing out the value of Date() in a Playground. Would love some help here. Thanks!










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm new to Firestore and since it doesn't seem like it has a native createdAt/updatedAt as part of a document, I'm creating them when I create the new document. Using a straight up Date() as the value for my initial dictionary that I save to Firestore obviously gives me a localized date/time – UTC -500, for example.



      Firestore stores this as November 19, 2018 at 5:14:54 PM UTC-5



      Is there a specific date format that Firestore likes in order to save something as a Timestamp and so that I will be able to sort on it later?



      I tried using "yyyy-MM-dd HH:mm:ss Z" as the dateFormat from just printing out the value of Date() in a Playground. Would love some help here. Thanks!










      share|improve this question















      I'm new to Firestore and since it doesn't seem like it has a native createdAt/updatedAt as part of a document, I'm creating them when I create the new document. Using a straight up Date() as the value for my initial dictionary that I save to Firestore obviously gives me a localized date/time – UTC -500, for example.



      Firestore stores this as November 19, 2018 at 5:14:54 PM UTC-5



      Is there a specific date format that Firestore likes in order to save something as a Timestamp and so that I will be able to sort on it later?



      I tried using "yyyy-MM-dd HH:mm:ss Z" as the dateFormat from just printing out the value of Date() in a Playground. Would love some help here. Thanks!







      swift google-cloud-firestore






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 1:32









      rmaddy

      237k27308374




      237k27308374










      asked Nov 19 at 22:40









      Zack Shapiro

      1,07173982




      1,07173982
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          A Timestamp object doesn't have a date format. It's just a measurement of a number of seconds since Unix epoch, plus some number of nanoseconds. It does not accept a formatted time. If you have a formatted time, you will have to parse it to get a Timestamp object in return.`



          The date format you're seeing in the console is just the way the console is choosing to format it. If you want to format a Timestamp for display, you'll need to do that yourself.






          share|improve this answer





















            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%2f53383685%2fturning-a-localized-date-to-a-timestamp-in-firebase%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








            up vote
            1
            down vote



            accepted










            A Timestamp object doesn't have a date format. It's just a measurement of a number of seconds since Unix epoch, plus some number of nanoseconds. It does not accept a formatted time. If you have a formatted time, you will have to parse it to get a Timestamp object in return.`



            The date format you're seeing in the console is just the way the console is choosing to format it. If you want to format a Timestamp for display, you'll need to do that yourself.






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              A Timestamp object doesn't have a date format. It's just a measurement of a number of seconds since Unix epoch, plus some number of nanoseconds. It does not accept a formatted time. If you have a formatted time, you will have to parse it to get a Timestamp object in return.`



              The date format you're seeing in the console is just the way the console is choosing to format it. If you want to format a Timestamp for display, you'll need to do that yourself.






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                A Timestamp object doesn't have a date format. It's just a measurement of a number of seconds since Unix epoch, plus some number of nanoseconds. It does not accept a formatted time. If you have a formatted time, you will have to parse it to get a Timestamp object in return.`



                The date format you're seeing in the console is just the way the console is choosing to format it. If you want to format a Timestamp for display, you'll need to do that yourself.






                share|improve this answer












                A Timestamp object doesn't have a date format. It's just a measurement of a number of seconds since Unix epoch, plus some number of nanoseconds. It does not accept a formatted time. If you have a formatted time, you will have to parse it to get a Timestamp object in return.`



                The date format you're seeing in the console is just the way the console is choosing to format it. If you want to format a Timestamp for display, you'll need to do that yourself.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 19 at 23:08









                Doug Stevenson

                68.2k880100




                68.2k880100






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53383685%2fturning-a-localized-date-to-a-timestamp-in-firebase%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







                    Popular posts from this blog

                    Create new schema in PostgreSQL using DBeaver

                    Deepest pit of an array with Javascript: test on Codility

                    Costa Masnaga