JavaScript Date Objects And Date Format

In this chapter we will talk on javascript date object, is clling method and format include in it for end users. This is javascript online tutorial important topic that is used by numbers of peoples.

Let’s go through the exmaple, syntax and functionalty implementation of javascript date object format.

Javascript Date Object

var dte = new Date();

New Date can be show in 4 ways that is passing date format and it will look like below:

new Date()
new Date(year, month, day, hours, minutes, seconds, milliseconds)
new Date(milliseconds)
new Date(date string)


If you want to show default date what will come when pass into date object then.

var dte = new Date(2021, 04, 04, 04, 33, 30, 0);
document.getElementById("darkweb").innerHTML = dte;


Tue May 04 2021 04:33:30 GMT+0530 (India Standard Time)


If you want to get date with specify year and month:

var dte = new Date(2021, 04);
document.getElementById("darkweb").innerHTML = dte;


Sat May 01 2021 00:00:00 GMT+0530 (India Standard Time)

The other date format we can use:

new Date(dateString)
new Date(milliseconds)

Date automatically converted to a string

var dte = new Date();
document.getElementById("darkweb").innerHTML = dte.toString();

Converts a date to a UTC string

var dte = new Date();
document.getElementById("darkweb").innerHTML = dte.toUTCString();

Converts a date to a readable format

var dte = new Date();
document.getElementById("darkweb").innerHTML = dte.toDateString();

Date Methods

getFullYear()Get the year as a four digit number (yyyy)
getMonth()Get the month as a number (0-11)
getDate()Get the day as a number (1-31)
getHours()Get the hour (0-23)
getMinutes()Get the minute (0-59)
getSeconds()Get the second (0-59)
getMilliseconds()Get the millisecond (0-999)
getTime()Get the time
getDay()Get the weekday as a number (0-6)

Hope this chapter will help you to learn javascript date and you will like our js tutorial and follow us on the Facebook social network to get more javascript news from us.

Stay in touch. Ask Questions.
Lean on us for help, strategies and expertise.

Leave a Reply

Your email address will not be published. Required fields are marked *