Javascript Date

JavaScript Date

In JavaScript Date Object is data type build into the JavaScript language. Data object are created with the new Date(). JavaScript Date instance that represents a single moment in time. JavaScript date object can only be instantiated by calling JavaScript as a constructor. Syntax We can use following syntaxes to create a Date object using Date() constructor.
new Date();  
new Date(value);  
new Date(dateString);  
new Date(year, month, day, hours, minutes, seconds, milliseconds);

NOTE: Parameters in bracket is always optional.

Here descriptions of parameter:


It representing the number of milliseconds since 1 January 2017 00:00:00 UTC, with leap seconds ignored.


String value representing a date. The string should be in a format recognized by the Date.parse()method.


Integer value representing the year. Value from 0 to 99 map of the years 2000 to 2099.


Integer value representing the month, beginning with 0 for January to 11 for December.


Optional. Integer value representing the day of the month.


Optional. Integer value representing the hours of the day.


Optional. Integer value representing the minute segment of a time.


Optional. Integer value representing the second segment of a time.


Optional. Integer value representing the millisecond segment of a time. Exmple of Date
<!DOCTYPE html>  
var date=new Date();    
var day=date.getDate();    
var month=date.getMonth()+1;    
var year=date.getFullYear();    
document.write("<br>Date: "+day+"/"+month+"/"+year);    
Try Now Output
Date: 27/11/2017
Example of current time
<!DOCTYPE html>  
Current Time: <span id="txt"></span>  
var today=new Date();    
var h=today.getHours();    
var m=today.getMinutes();    
var s=today.getSeconds();    
Try Now Output
Current Time: 10:34:50