Here we show how you can display current date and time in your web page with the help of simple java script code.
Sometime we need to display current date and time in our html code, it is a very common task to show current date and time in your website.
Create the Date Object
Date objects are created with the new Date() constructor.
Get Method to Show the current Date in JavaScript
If you want to get the date in the YYYY-MM-DD format. Use below code:
getFullYear()– Provides current year like 2021.
getMonth()– Provides current month values 0-11. Where 0 for Jan and 11 for Dec. So added +1 to get result.
getDate()– Provides day of the month values 1-31.
Below code for show current date in HTML.
Inflay.com | Display Current Date And Time In HTML By JavaScript
Get current date using JavaScript.
Display Hours, Minutes, and Seconds using JavaScript
Use the following script to get the current time using JavaScript in HH:MM:SS format.
getHours()– Provides current hour between 0-23.
getMinutes()– Provides current minutes between 0-59.
getSeconds()– Provides current seconds between 0-59.
Below code for show current time in HTML.
Inflay.com | Display Current Date And Time In HTML By JavaScript
Get current time using JavaScript.
Display the Full Current Date and Time in JavaScript
show full date and time in the YYYY-MM-DD and HH:MM:SS formats.
Below Code Show Current Date and Time Both in JavaScript
Inflay.com | Display Current Date And Time In HTML By JavaScript
Get current date and time using JavaScript.
I hope this article helps you.
Thanks for visiting Inflay.com .