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
The Date.now() static method returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.
🌐
W3Schools
w3schools.com › jsref › jsref_now.asp
JavaScript Date now() Method
Date.now() returns the number of milliseconds since January 1, 1970.
Discussions

How do I get the current date in JavaScript? - Stack Overflow
It returns a JSON datetime. toUTCString() returns as utc datetime. 2014-02-18T09:08:57.09Z+00:00 ... It doesn't consider TimezoneOffset. At my time of testing, I was seeking "now" and I got "yesterday". More on stackoverflow.com
🌐 stackoverflow.com
javascript - performance.now() vs Date.now() - Stack Overflow
Date.now() is relative to the Unix epoch (1970-01-01T00:00:00Z) and dependent on system clock. Use cases include same old date manipulation ever since the beginning of JavaScript. More on stackoverflow.com
🌐 stackoverflow.com
Getting current date and time in JavaScript - Stack Overflow
Instead of those monstrous functions, we now can use moment.js to get the current date, which actually makes it very easy. All that has to be done is including moment.js in our project and get a well formated date, for example, by: ... I think that makes it way easier to handle dates in javascript. More on stackoverflow.com
🌐 stackoverflow.com
JavaScript Date(Date)
Your code breaks if it's the first day of the month. And yeah, the built-in JavaScript date type is pretty garbage. I recommend using moment.js instead. More on reddit.com
🌐 r/programminghorror
25
48
August 8, 2017
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Due to the differing lengths of ... a number of issues, and should be thoroughly researched before being attempted. ... // Using Date objects const start = Date.now(); // The event to time goes here: doSomethingForALongTime(); const end = Date.now(); const elapsed = end - start; ...
🌐
Toptal
toptal.com › developers › software › definitive-guide-to-datetime-manipulation
How to get the Timestamp And Date in Javascript: JS DateTime | Toptal®
December 2, 2020 - This makes JavaScript date-from-timestamp and JavaScript timestamp-to-date conversion straightforward, provided the UTC time zone is used. If you don’t intend to support <IE8, you can use Date.now() to directly get the time stamp without having to create a new Date object.
🌐
Capacitor
capacitorjs.com
Capacitor by Ionic - Cross-platform apps with web technology
Capacitor is an open source native runtime for building Web Native apps. Create cross-platform iOS, Android, and Progressive Web Apps with JavaScript, HTML, and CSS.
Find elsewhere
🌐
npm
npmjs.com › package › date-fns
date-fns - npm
Modern JavaScript date utility library. Latest version: 4.1.0, last published: a year ago. Start using date-fns in your project by running `npm i date-fns`. There are 24815 other projects in the npm registry using date-fns.
      » npm install date-fns
    
Published   Sep 17, 2024
Version   4.1.0
🌐
CodeToFun
codetofun.com › js › date-now
JavaScript Date now() Method | CodeToFun
November 21, 2024 - In this guide, we'll explore the now() method, understand its syntax, and examine how to effectively use it in your JavaScript applications. The now() method of the Date object returns the current timestamp in milliseconds.
🌐
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().
🌐
Moment.js
momentjs.com
Moment.js | Home
Moment.js is freely distributable under the terms of the MIT license
🌐
Edgecompute
js-compute-reference-docs.edgecompute.app › date() › date.now()
Date.now() | @fastly/js-compute
The static Date.now() method returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-now-method
JavaScript Date now() Method - GeeksforGeeks
July 11, 2025 - The Date.now() method in JavaScript returns the current timestamp in milliseconds since January 1, 1970.
🌐
Nikita Hlopov
nikitahl.com › get-the-current-date-in-javascript
How to get the current date in JavaScript (Time, Day, Month, Year)
To get the current date in JavaScript you’ll only need the Vanilla JavaScript Date API. All the information about the current date can be accessed in one lin...
🌐
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 - 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.
🌐
Colorado DMV
dmv.colorado.gov › mydmv
myDMV Help | Department of Revenue - Motor Vehicle
Use the "sent from" feature to select a date or date range.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
There’s a special method Date.now() that returns the current timestamp. It is semantically equivalent to new Date().getTime(), but it doesn’t create an intermediate Date object.
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - The Date.now() static method returns the current timestamp in milliseconds.
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.

🌐
Js
flatpickr.js.org › examples
Examples - flatpickr
The selected date will get parsed from the input’s value or the defaultDate option.