0

How can I get the date in javascript format: day, date month example: Friday, 12 March

This gives me 12/3

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
    <script>    
    var d = new Date();
     
    var date = d.getUTCDate();
    var month = d.getUTCMonth() + 1; // Since getUTCMonth() returns month from 0-11 not 1-12

     
    var dateStr = date + "/" + month;
    document.write(dateStr);
    </script>
</body>
</html>  
2
  • 1
    This is what you need. Commented Mar 12, 2021 at 11:56
  • 1
    Either use a locale specific format, i.e. (new Date()).toLocaleDateString('en-US', { weekday:'long', day: 'numeric', month:'long', }) which gives you 'Friday, March 12' or build your custom format by formatting each individual field as you want. Commented Mar 12, 2021 at 12:06

2 Answers 2

2

This uses locale date's formate.

const date = new Date();
var options = {
  weekday: 'long',
  month: 'long',
  day: 'numeric'
};

console.log(date.toLocaleDateString("default", options));
 

Or use date.toLocaleDateString('en-US', options)

Sign up to request clarification or add additional context in comments.

1 Comment

Op wants "Friday, 12 March"
0

try {date|date:"dd/MM/yyyy:HH:mm:ss"}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.