Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
JavaScript Date Reference
Next article icon

JavaScript Date Reference

Last Updated : 18 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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);

Output
2025-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.

ConstructorDescription
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.
PropertiesDescription
constructorReturns 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 MethodsDescription
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 MethodsDescription
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.

Next Article
JavaScript Date Reference
author
kartik
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-date

Similar Reads

    JavaScript Date Objects
    In JavaScript, the Date object is a built-in object that allows you to work with dates and times. It provides a variety of methods to handle dates, compare them, manipulate them, and format them.The Date object in JavaScript represents a single point in time. It provides various functionalities to w
    6 min read
    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 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
    java.time.LocalDate Class in Java
    Java is the most popular programming language and widely used programming language. Java is used in all kind of application like as mobile application, desktop application, web application. In this Java java.time.LocalDate class is imported which represents to display the current date. java.time: It
    4 min read
    HijrahChronology date() method in Java with Example : Set - 2
    The date() method of java.time.chrono.HijrahChronology class is used get the local date according to Hijrah calendar system from the another TemporalAccessor object . Syntax: public HijrahDate date(TemporalAccessor temporal) Parameter: This method takes the object of any temporal accessor as a param
    2 min read
    HijrahDate from() method in Java with Example
    The from() method of java.time.chrono.HijrahDate class is used to get the hijrah date according to the hijrah calendar system for the particular temporal object. Syntax: public static HijrahDate from( TemporalAccessor temporal) Parameter: This method takes the object of any temporal accessor on the
    2 min read
    IsoChronology date(TemporalAccessor) method in Java with Example
    The date() method of java.time.chrono.IsoChronology class is used get the local date according to ISO system from the another TemporalAccessor object. Syntax: public LocalDate date(TemporalAccessor temporal) Parameter: This method takes the object of any temporal accessor as a parameter. Return Valu
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences