Timestamp intervals in JavaScript









up vote
2
down vote

favorite












How can I pick a past date that is a Tuesday or Monday, then get timestamps at 2 week intervals in JavaScript? I am using faker.js. I can only get a date in the past in years, 2 and 1 as shown below.



const releaseStart1 = new Date(faker.date.past(2, new Date(Date.now())));
const releaseEnd1 = new Date(faker.date.past(1, new Date(Date.now())));










share|improve this question





















  • What is the reason you would use faker for that?
    – str
    Nov 9 at 14:16










  • Good point. It was the only way I knew of to get dates in the past. It would actually be better, if i could pick a Tuesday 3, 5, or however many months ago specifically.
    – Matthew Divertie
    Nov 9 at 14:25














up vote
2
down vote

favorite












How can I pick a past date that is a Tuesday or Monday, then get timestamps at 2 week intervals in JavaScript? I am using faker.js. I can only get a date in the past in years, 2 and 1 as shown below.



const releaseStart1 = new Date(faker.date.past(2, new Date(Date.now())));
const releaseEnd1 = new Date(faker.date.past(1, new Date(Date.now())));










share|improve this question





















  • What is the reason you would use faker for that?
    – str
    Nov 9 at 14:16










  • Good point. It was the only way I knew of to get dates in the past. It would actually be better, if i could pick a Tuesday 3, 5, or however many months ago specifically.
    – Matthew Divertie
    Nov 9 at 14:25












up vote
2
down vote

favorite









up vote
2
down vote

favorite











How can I pick a past date that is a Tuesday or Monday, then get timestamps at 2 week intervals in JavaScript? I am using faker.js. I can only get a date in the past in years, 2 and 1 as shown below.



const releaseStart1 = new Date(faker.date.past(2, new Date(Date.now())));
const releaseEnd1 = new Date(faker.date.past(1, new Date(Date.now())));










share|improve this question













How can I pick a past date that is a Tuesday or Monday, then get timestamps at 2 week intervals in JavaScript? I am using faker.js. I can only get a date in the past in years, 2 and 1 as shown below.



const releaseStart1 = new Date(faker.date.past(2, new Date(Date.now())));
const releaseEnd1 = new Date(faker.date.past(1, new Date(Date.now())));







javascript datetime unix-timestamp faker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 14:07









Matthew Divertie

324




324











  • What is the reason you would use faker for that?
    – str
    Nov 9 at 14:16










  • Good point. It was the only way I knew of to get dates in the past. It would actually be better, if i could pick a Tuesday 3, 5, or however many months ago specifically.
    – Matthew Divertie
    Nov 9 at 14:25
















  • What is the reason you would use faker for that?
    – str
    Nov 9 at 14:16










  • Good point. It was the only way I knew of to get dates in the past. It would actually be better, if i could pick a Tuesday 3, 5, or however many months ago specifically.
    – Matthew Divertie
    Nov 9 at 14:25















What is the reason you would use faker for that?
– str
Nov 9 at 14:16




What is the reason you would use faker for that?
– str
Nov 9 at 14:16












Good point. It was the only way I knew of to get dates in the past. It would actually be better, if i could pick a Tuesday 3, 5, or however many months ago specifically.
– Matthew Divertie
Nov 9 at 14:25




Good point. It was the only way I knew of to get dates in the past. It would actually be better, if i could pick a Tuesday 3, 5, or however many months ago specifically.
– Matthew Divertie
Nov 9 at 14:25












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Look at using moment as it will let you do something like



let date = moment().subtract(7, 'days').format();



Which will return the date. You can use days weeks months seconds minutes hours etc



https://momentjs.com/docs/






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%2f53227276%2ftimestamp-intervals-in-javascript%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Look at using moment as it will let you do something like



    let date = moment().subtract(7, 'days').format();



    Which will return the date. You can use days weeks months seconds minutes hours etc



    https://momentjs.com/docs/






    share|improve this answer


























      up vote
      1
      down vote



      accepted










      Look at using moment as it will let you do something like



      let date = moment().subtract(7, 'days').format();



      Which will return the date. You can use days weeks months seconds minutes hours etc



      https://momentjs.com/docs/






      share|improve this answer
























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Look at using moment as it will let you do something like



        let date = moment().subtract(7, 'days').format();



        Which will return the date. You can use days weeks months seconds minutes hours etc



        https://momentjs.com/docs/






        share|improve this answer














        Look at using moment as it will let you do something like



        let date = moment().subtract(7, 'days').format();



        Which will return the date. You can use days weeks months seconds minutes hours etc



        https://momentjs.com/docs/







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 at 14:35

























        answered Nov 9 at 14:29









        Noel Kriegler

        301110




        301110



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227276%2ftimestamp-intervals-in-javascript%23new-answer', 'question_page');

            );

            Post as a guest














































































            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo