Use new Date() to generate a new Date object containing the current date and time.

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();

today = mm + '/' + dd + '/' + yyyy;
document.write(today);

This will give you today's date in the format of mm/dd/yyyy.

Simply change today = mm +'/'+ dd +'/'+ yyyy; to whatever format you wish.

Answer from Samuel Meddows on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript | MDN
For example, with reduced time precision, the result of Date.now() will always be a multiple of 2, or a multiple of 100 (or privacy.resistFingerprinting.reduceTimerPrecision.microseconds) with privacy.resistFingerprinting enabled. js · // reduced time precision (2ms) in Firefox 60 Date.now(); // Might be: // 1519211809934 // 1519211810362 // 1519211811670 // …
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
// Using Date objects const start = Date.now(); // The event to time goes here: doSomethingForALongTime(); const end = Date.now(); const elapsed = end - start; // elapsed time in milliseconds · js · // Using built-in methods const start = new Date(); // The event to time goes here: ...
🌐
W3Schools
w3schools.com › jsref › jsref_now.asp
JavaScript Date now() Method
constructor() extends static super JS Dates · new Date() constructor getDate() getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getTimezoneOffset() getUTCDate() getUTCDay() getUTCFullYear() getUTCHours() getUTCMilliseconds() getUTCMinutes() getUTCMonth() getUTCSeconds() now() parse() prototype setDate() setFullYear() setHours() setMilliseconds() setMinutes() setMonth() setSeconds() setTime() setUTCDate() setUTCFullYear() setUTCHours() setUTCMilliseconds() setUTCMinutes() setUTCMonth() setUTCSeconds() toDateString() toISOString() toJSON() toLocaleDateString() toLocaleTimeString() toLocaleString() toString() toTimeString() toUTCString() UTC() valueOf() JS Function ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
When no parameters are provided, the newly-created Date object represents the current date and time as of the time of instantiation. The returned date's timestamp is the same as the number returned by Date.now().
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
It is semantically equivalent to new Date().getTime(), but it doesn’t create an intermediate Date object. So it’s faster and doesn’t put pressure on garbage collection. It is used mostly for convenience or when performance matters, like in games in JavaScript or other specialized applications. ... let start = Date.now(); // milliseconds count from 1 Jan 1970 // do the job for (let i = 0; i < 100000; i++) { let doSomething = i * i * i; } let end = Date.now(); // done alert( `The loop took ${end - start} ms` ); // subtract numbers, not dates
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-new-date-and-datenow-in-javascript
Difference Between new Date() and Date.now() in JavaScript - GeeksforGeeks
August 5, 2025 - Example: This example shows the use of new Date() constructor. ... The Date.now() method returns the numeric value corresponding to the current time—the number of the milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - Master JavaScript's Date object with this comprehensive guide. Learn to manipulate, format, and compute dates and times effectively, overcoming common
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-now-method
JavaScript Date now() Method - GeeksforGeeks
July 11, 2025 - // Use of Date.now() method let d = Date(Date.now()); // Converting the number of millisecond in date string a = d.toString() // Printing the current date console.log("The current date is: " + a) ... The code snippet generates a new Date object ...
🌐
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
Educative
educative.io › answers › what-is-datenow-in-javascript
What is Date.now() in Javascript?
In Javascript, the .now() method is a Date static method that returns the number of milliseconds since January 1, 1970 00:00:00 UTC.
🌐
W3Schools
w3schools.com › js › js_dates.asp
W3Schools.com
By default, JavaScript will use the browser's time zone and display a date as a full text string: You will learn much more about how to display dates, later in this tutorial. Date objects are created with the new Date() constructor.
🌐
Day.js
day.js.org › docs › en › parse › now
Now · Day.js
Calling dayjs() without parameters returns a fresh Day.js object with the current date and time. var now = dayjs() This is essentially the same as calling dayjs(new Date()). Day.js treats dayjs(undefined) as dayjs() due to that function parameters default to undefined when not passed in.
🌐
Medium
medium.com › @techsolutionstuff › node-js-get-current-date-and-time-example-e7893d95c174
Node JS Get Current Date And Time Example | by Techsolutionstuff | Medium
September 29, 2023 - Get the current timestamp using Date.now() method. Note that this method returns the timestamp in milliseconds.
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
JS Examples JS HTML DOM JS HTML ... Prep JS Bootcamp JS Certificate JS Reference ... In JavaScript, date objects are created with new Date()....
🌐
Sololearn
sololearn.com › en › Discuss › 2967337 › new-date-vs-datenow
new Date vs Date.now() | Sololearn: Learn to code for FREE!
• new Date() - creates a Date object representing the current date/time • Date.now() - returns the number of milliseconds since midnight 01 January, 1970 UTC As a matter of style, I found it clearer to use Date.now() in code that deals with ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getTime
Date.prototype.getTime() - JavaScript | MDN
The getTime() method of Date instances returns the number of milliseconds for this date since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC. const moonLanding = new Date("July 20, 69 20:17:40 GMT+00:00"); // Milliseconds since Jan 1, 1970, 00:00:00.000 GMT console.log(moonLanding.getTime()); // Expected output: -14182940000
Top answer
1 of 16
789

.getMonth() returns a zero-based number so to get the correct month you need to add 1, so calling .getMonth() in may will return 4 and not 5.

So in your code we can use currentdate.getMonth()+1 to output the correct value. In addition:

  • .getDate() returns the day of the month <- this is the one you want
  • .getDay() is a separate method of the Date object which will return an integer representing the current day of the week (0-6) 0 == Sunday etc

so your code should look like this:

var currentdate = new Date(); 
var datetime = "Last Sync: " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/" 
                + currentdate.getFullYear() + " @ "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":" 
                + currentdate.getSeconds();

JavaScript Date instances inherit from Date.prototype. You can modify the constructor's prototype object to affect properties and methods inherited by JavaScript Date instances

You can make use of the Date prototype object to create a new method which will return today's date and time. These new methods or properties will be inherited by all instances of the Date object thus making it especially useful if you need to re-use this functionality.

// For todays date;
Date.prototype.today = function () { 
    return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
}

// For the time now
Date.prototype.timeNow = function () {
     return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
}

You can then simply retrieve the date and time by doing the following:

var newDate = new Date();
var datetime = "LastSync: " + newDate.today() + " @ " + newDate.timeNow();

Or call the method inline so it would simply be -

var datetime = "LastSync: " + new Date().today() + " @ " + new Date().timeNow();
2 of 16
548

To get time and date you should use

    new Date().toLocaleString();

>> "09/08/2014, 2:35:56 AM"

To get only the date you should use

    new Date().toLocaleDateString();

>> "09/08/2014"

To get only the time you should use

    new Date().toLocaleTimeString();

>> "2:35:56 AM"

Or if you just want the time in the format hh:mm without AM/PM for US English

    new Date().toLocaleTimeString('en-US', { hour12: false, 
                                             hour: "numeric", 
                                             minute: "numeric"});
>> "02:35"

or for British English

    new Date().toLocaleTimeString('en-GB', { hour: "numeric", 
                                             minute: "numeric"});

>> "02:35"

Read more here.