Home > Back-end >  how do I get only the day displayed?
how do I get only the day displayed?

Time:12-03

I am absolutely new and have not found a suitable answer yet (or was too blind to see it). I would like the date to be displayed to me in dd/mm/yyyy format. Currently it shows me the day in milliseconds though? Can someone help me?

var oneweekago = new Date();
var month = oneweekago.getMonth()  1
var day = oneweekago.setDate(oneweekago.getDate() - 7)
var year = oneweekago.getFullYear()
document.write(day   "/"   month   "/"   year)
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

I believe you are looking for oneWeekAgo.toLocaleDateString()

var oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7)
document.write(oneWeekAgo.toLocaleDateString())

CodePudding user response:

This piece of code displays: 03/12/2021

<script>
    var today = new Date();
    
    var dd = today.getDate();
    var mm = today.getMonth()   1;
    var yyyy = today.getFullYear();
    
    var today = dd   '/'   mm   '/'   yyyy;

    console.log(today)
</script>
  • Related