How to insert today's date into a URL?

后端 未结 6 517
陌清茗
陌清茗 2020-12-11 23:11

I have a url that change every day based on today\'s date, for example:

http://www.newspaper.com/edition/20141227.ht         


        
6条回答
  •  被撕碎了的回忆
    2020-12-11 23:38

    You can try the below code. Hope this helps.

    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth()+1; //January is 0!
    var yyyy = today.getFullYear();
    if(dd<10){dd='0'+dd};
    if(mm<10){mm='0'+mm};
    today = yyyy+mm+dd;
    var new_url=document.URL+"/"+today+".html";
    console.log(new_url);
    

提交回复
热议问题