format date to string javascript code example
Example 1: javascript date to string
const event = new Date(1993, 6, 28, 14, 39, 7);
console.log(event.toString());
console.log(event.toDateString());
Example 2: convert date to string javascript
var d = new Date();
var n = d.toDateString();
Example 3: javascript format date
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today = new Date();
console.log(today.toLocaleDateString("en-US"));
console.log(today.toLocaleDateString("en-US", options));
console.log(today.toLocaleDateString("hi-IN", options));
Example 4: javascript date format
const d = new Date('2010-08-05')
const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d)
const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)
console.log(`${da}-${mo}-${ye}`)
Example 5: javascript full date as string
<p>The toDateString() method converts a date to a date string:</p>
<p id="demo"></p>
<script>
var d = new Date();
document.getElementById("demo").innerHTML = d.toDateString();
</script>