JavaScript Tutorial

Define JavaScript

JS Arithmetic Exercise

JavaScript Comment

JavaScript Variable

JavaScript Operators

Conditional Statements

Logical Operators

JavaScript Slider

JS Login Form

JS Popup Boxes

JavaScript Loops

JavaScript Arrays

JS Mouse Events

JS Keyboard Events

Styling Elements

External JavaScript

JS Noscript Tag

JS String Functions

JS Math Functions

JS Random

JS Date Functions


JS Assignment

JS Question-Answer

Page Stats

Visitor: 416

JavaScript Date Functions

Example 1: Display Date and Time on Button Click.

var d = new Date();
document.getElementById("demo").innerHTML = d;
document.getElementById("demo").innerHTML = d.toDateString();

Date and Time can be extract in parts also. Common javascript date and time functions are:

var d = new Date();
document.getElementById("demo").innerHTML = d.getDay();
document.getElementById("demo").innerHTML = d.getFullYear();
document.getElementById("demo").innerHTML = d.getTime();

The setDate() function can be used to add days to a date:
var d = new Date();
d.setDate(d.getDate() + 50);
document.getElementById("demo").innerHTML = d; 

Updated: 12-Dec-21