Tue Dec 20 2022 15:46:54 GMT+0530 (India Standard Time)
Sample Code
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>Using new Date()</h2>
<p>new Date() without arguments, creates a date object with the current date and time:</p>
<p id="demo"></p>
<script>
const d = new Date();
document.getElementById("demo").innerHTML = d;
</script>
</body>
</html>
Output
JavaScript Dates
Using new Date()
new Date() without arguments, creates a date object with the current date and time:
Tue Dec 20 2022 15:52:32 GMT+0530 (India Standard Time)
JavaScript Date Output
By default, JavaScript will use the browser's time zone and display a date as a full text string.
Tue Dec 20 2022 15:46:54 GMT+0530 (India Standard Time)
Creating Date Objects
Date objects are created with the new Date() constructor.
There are 9 ways to create a new date object.
new Date()
new Date(date string)
new Date(year,month)
new Date(year,month,day)
new Date(year,month,day,hours)
new Date(year,month,day,hours,minutes)
new Date(year,month,day,hours,minutes,seconds)
new Date(year,month,day,hours,minutes,seconds,ms)
new Date(milliseconds)
JavaScript new Date()
new Date() creates a date object with the current date and time.
Sample Code
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>Using new Date()</h2>
<p>Create a new date object with the current date and time:</p>
<p id="demo"></p>
<script>
const d = new Date();
document.getElementById("demo").innerHTML = d;
</script>
</body>
</html>
Output
Using new Date()
Create a new date object with the current date and time:
Fri Dec 23 2022 15:56:15 GMT+0530 (India Standard Time)
Related Searches to JavaScript Date Objects - What are date objects in JavaScript
javascript date objects javascript date reference javascript date object what are date objects in javascript which javascript object works with dates how to declare a date object in javascript how to display date object in javascript what is the javascript date object javascript date format javascript string to date javascript date now date in java javascript time format new date javascript form