Skip to content
-
JavaScript Date Reference
Last Updated :
14 Jul, 2025
The JavaScript Date object is important for handling dates and times in web development. It provides various methods to create, manipulate, and format dates. Understanding the Date object and its methods allows you to work effectively with dates and times in your applications. This guide covers the key features and methods of the JavaScript Date object, helping you to manage date and time data efficiently.
Syntax:
new Date();
Example: If nothing is given as the parameter is given, it returns the present date and time.
JavaScript
// If nothing as a parameter is given,
// it represents the present date and time.
let A = new Date();
console.log(A);
Output2025-04-18T09:18:48.488Z
The complete list of JavaScript Date methods and properties are listed below:
JavaScript Date Constructor: A constructor gets called when an object is created using the new keyword.
Constructor | Description |
---|
Date() | Create a Date instance or return a string representing the current time. |
JavaScript Date Properties: A JavaScript property is a member of an object that associates a key with a value.
- Instance Properties: An instance property is a property that has a new copy for every new instance of the class.
Properties | Description |
---|
constructor | Returns the constructor function for an object. |
JavaScript Date Methods: JavaScript methods are actions that can be performed on objects.
- Static Method: If the method is called using the Date class itself then it is called a static method.
Static Methods | Description |
---|
now() | Return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. |
parse() | Return the time difference in milliseconds from, January 1, 1970, till the date we provide. |
UTC() | Return the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time. |
- Instance Method: If the method is called on an instance of a date object then it is called an instance method.
Instance Methods | Description |
---|
getDate() | Fetch the date of a month from a given Date object. |
getDay() | Fetch the day of a week(0 to 6) from a given Date object. |
getFullYear() | Fetch the year from a given Date object. |
getHours() | Return the hours from a given Date object. |
getMilliseconds() | Fetch the milliseconds from a given Date object. |
getMinutes() | Fetch the minutes from the given Date object. |
getMonth() | Fetch the month(0 to 11) from the given Date object. |
getSeconds() | Fetch the seconds from the given Date object. |
getTime() | Return the number of milliseconds since 1 January 1970 . |
getTimezoneOffset() | Return the time difference between in minutes. |
getUTCDate() | Fetch the date of a month according to universal time from a given Date object. |
getUTCDay() | Fetch the date of a month according to universal time from a given Date object. |
getUTCFullYear() | Fetch the year according to universal time from a given Date object. |
getUTCHours() | Fetch the hours according to universal time from a given Date object. |
getUTCMilliseconds() | Fetch the millisecond according to universal time from a given Date object. |
getUTCMinutes() | Fetch the minutes according to universal time from a given Date object. |
getUTCMonth() | Fetch the month according to universal time from a given Date object. |
getUTCSeconds() | Fetch the second according to universal time from a given Date object |
getYear() | Get the year on a specified date according to universal time. |
setDate() | Set the date of a month into a date object which is created using date() constructor. |
setFullYear() | Set year into a date object which is created using Date() constructor. |
setHours() | Set hours into a date object which is created using the Date() constructor. |
setMilliseconds() | Set milliseconds into a date object which are created using date() constructor. |
setMinutes() | Set minutes into a Date object which is created using Date() constructor. |
setMonth() | Set month into a date object which is created using the Date() constructor. |
setSeconds() | Set seconds into a Date object which is created using Date() constructor. |
setUTCDate() | Set date of a month according to universal time into a date object. |
setUTCFullYear() | Set year into a date object according to universal time. |
setUTCHours() | Set hours into a date object according to universal time. |
setUTCMilliseconds() | Set milliseconds according to universal time into a date object. |
setUTCMinutes() | Set minutes according to universal time into a date object. |
setUTCMonth() | Set month according to universal time into a date object. |
setUTCSeconds() | Set seconds according to universal time into a date object. |
setYear() | Set the year in a specified date according to universal time. |
toDateString() | Convert the given date object’s contents of the date portion into a string. |
toISOString() | Convert the given date object’s contents into a string in ISO format (ISO 8601). |
toJSON() | Convert the given date object’s contents into a string. |
toLocaleDateString() | Convert a date to a string. |
toLocaleTimeString() | Fetch the time from a given Date object. |
toLocaleString() | Convert a date and time to a string. |
toString() | Convert the given date object’s contents into a string. |
toTimeString() | Return the time portion of the given date object in English. |
toUTCString() | Convert the given date object’s contents into a string according to the universal time zone UTC. |
valueOf() | Get the number of milliseconds between 1 January 1970 00:00:00 UTC and the given date. |
Similar Reads
JavaScript Date UTC() Method In JavaScript, the Date.UTC() method is used to create a date object representing a specified date and time in UTC (Coordinated Universal Time). It accepts the year, month, day, hour, minute, second, and millisecond components of the date and returns the number of milliseconds since January 1, 1970,
4 min read
JavaScript Date toDateString() Method The date.toDateString() method converts the given date objectâs contents of the date portion into a string. The date object is created using the date() constructor. Syntax: dateObj.toDateString() Parameters: This method does not accept any parameter. It is just used with a Date object created using
4 min read
JavaScript Date toDateString() Method The date.toDateString() method converts the given date objectâs contents of the date portion into a string. The date object is created using the date() constructor. Syntax: dateObj.toDateString() Parameters: This method does not accept any parameter. It is just used with a Date object created using
4 min read
JavaScript Date Programming Examples The JavaScript comes with a built-in datatype called the Date object. The Date object is created by using a new keyword, i.e. new Date() . The Date object can be used for date and time in terms of millisecond precision within 100 million days before or after 1/1/1970. JavaScript Date Programming Exa
5 min read
ChronoLocalDate getChronology() method in Java with Examples The getChronology() method of ChronoLocalDate interface in Java gets the chronology of this date, which is the ISO calendar system. Syntax: public IsoChronology getChronology() Parameter: This method does not accept any parameter. Return Value: It returns the ISO chronology and not null. Below progr
1 min read
Date class in Java (With Examples) The class Date represents a specific instant in time, with millisecond precision. The Date class of java.util package implements Serializable, Cloneable and Comparable interface. It provides constructors and methods to deal with date and time with java. Constructors Date() : Creates date object repr
3 min read
`;
$(commentSectionTemplate).insertBefore(".article--recommended");
}
loadComments();
});
});
function loadComments() {
if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) {
if (!isfollowingApiCall) {
isfollowingApiCall = true;
setTimeout(function(){
if (loginData && loginData.isLoggedIn) {
if (loginData.userName !== $('#followAuthor').val()) {
is_following();
} else {
$('.profileCard-profile-picture').css('background-color', '#E7E7E7');
}
} else {
$('.follow-btn').removeClass('hideIt');
}
}, 3000);
}
}
});
}
$(".accordion-header").click(function() {
var arrowIcon = $(this).find('.bottom-arrow-icon');
arrowIcon.toggleClass('rotate180');
});
});
window.isReportArticle = false;
function report_article(){
if (!loginData || !loginData.isLoggedIn) {
const loginModalButton = $('.login-modal-btn')
if (loginModalButton.length) {
loginModalButton.click();
}
return;
}
if(!window.isReportArticle){
//to add loader
$('.report-loader').addClass('spinner');
jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', {
PRACTICE_API_URL: practiceAPIURL,
PRACTICE_URL:practiceURL
},function(responseTxt, statusTxt, xhr){
if(statusTxt == "error"){
alert("Error: " + xhr.status + ": " + xhr.statusText);
}
});
}else{
window.scrollTo({ top: 0, behavior: 'smooth' });
$("#report_modal_content").show();
}
}
function closeShareModal() {
const shareOption = document.querySelector('[data-gfg-action="share-article"]');
shareOption.classList.remove("hover_share_menu");
let shareModal = document.querySelector(".hover__share-modal-container");
shareModal && shareModal.remove();
}
function openShareModal() {
closeShareModal(); // Remove existing modal if any
let shareModal = document.querySelector(".three_dot_dropdown_share");
shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" }));
document.querySelector(".hover__share-modal-container").append(
Object.assign(document.createElement('div'), { className: "share__modal" }),
);
document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" }));
const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"];
socialOptions.forEach((socialOption) => {
const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" });
const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` });
const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` });
const shareLink = (socialOption === "Copy Link") ?
Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) :
Object.assign(document.createElement('a'), { className: "link-container" });
if (socialOption === "LinkedIn") {
shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`);
shareLink.setAttribute('target', '_blank');
}
if (socialOption === "WhatsApp") {
shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
if (socialOption === "Twitter") {
shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
shareLink.append(icon, socialText);
socialContainer.append(shareLink);
document.querySelector(".share__modal").appendChild(socialContainer);
//adding copy url functionality
if(socialOption === "Copy Link") {
shareLink.addEventListener("click", function() {
var tempInput = document.createElement("input");
tempInput.value = window.location.href;
document.body.appendChild(tempInput);
tempInput.select();
tempInput.setSelectionRange(0, 99999); // For mobile devices
document.execCommand('copy');
document.body.removeChild(tempInput);
this.querySelector(".share__option-text").textContent = "Copied"
})
}
});
// document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu"));
}
function toggleLikeElementVisibility(selector, show) {
document.querySelector(`.${selector}`).style.display = show ? "block" : "none";
}
function closeKebabMenu(){
document.getElementById("myDropdown").classList.toggle("show");
}