🌐
W3Schools
w3schools.com › jsref › jsref_now.asp
JavaScript Date now() Method
Date.now() returns the number of milliseconds since January 1, 1970.
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
Date.now() returns the number of milliseconds since January 1, 1970.
🌐
W3Schools
w3schools.com › js › js_dates.asp
JavaScript Dates
February 4, 2026 - JavaScript stores dates as number of milliseconds since January 01, 1970. Zero time is January 01, 1970 00:00:00 UTC. One day (24 hours) is 86 400 000 milliseconds. Now the time is: milliseconds past January 01, 1970
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript - MDN - Mozilla
// This example takes 2 seconds to run const start = Date.now(); console.log("starting timer..."); // Expected output: "starting timer..." setTimeout(() => { const ms = Date.now() - start; console.log(`seconds elapsed = ${Math.floor(ms / 1000)}`); // Expected output: "seconds elapsed = 2" }, 2000); ... A number representing the timestamp, in milliseconds, of the current time. To offer protection against timing attacks and fingerprinting, the precision of Date.now() might get rounded depending on browser settings.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN - Mozilla
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 - ...
🌐
W3Schools
w3schoolsua.github.io › js › js_dates_en.html
JavaScript Date Objects. Lessons for beginners. W3Schools in English
JavaScript stores dates as number of milliseconds since January 01, 1970, 00:00:00 UTC (Universal Time Coordinated). Zero time is January 01, 1970 00:00:00 UTC. Now the time is: milliseconds past January 01, 1970
🌐
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.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-now-method
JavaScript Date now() Method - GeeksforGeeks
July 11, 2025 - The code snippet utilizes `Date.now()` to retrieve the current timestamp in milliseconds since the Unix epoch. It stores this value in variable `A` and prints it, indicating the elapsed milliseconds since the epoch.
🌐
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().
🌐
freeCodeCamp
freecodecamp.org › news › javascript-date-now-how-to-get-the-current-date-in-javascript
JavaScript Date Now – How to Get the Current Date in JavaScript
June 15, 2020 - One point to note about the getMonth() method is that it returns 0-indexed values (0-11) where 0 is for January and 11 for December. Hence the addition of 1 to normalize the month's value. now() is a static method of the Date object.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to use javascript to get the current date and time
How to Use JavaScript to Get the Current Date and Time
August 8, 2015 - In this script, Date.now() retrieves the current time in milliseconds since the UNIX epoch. Then, it passes this time value to the Date object to create a new Date instance representing the current date and time.
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.

🌐
W3Schools
w3schools.com › js › js_date_reference.asp
JavaScript Date Reference
Temporal Study Path Temporal Intro Temporal vs Date Temporal Now Temporal Instant Temporal PlainDate Temporal PlainTime Temporal PlainDateTime Temporal ZonedDateTime Temporal Duration Temporal Arithmetic Temporal Migrate Temporal Reference JS Arrays
🌐
W3Schools
w3schools.com › Js › js_date_formats.asp
JavaScript Date Formats
If you want to modify the time relative to UTC, remove the Z and add +HH:MM or -HH:MM instead: const d = new Date("2015-03-25T12:00:00-06:30"); Try it Yourself » · UTC (Universal Time Coordinated) is the same as GMT (Greenwich Mean Time). Omitting T or Z in a date-time string can give different results in different browsers. When setting a date, without specifying the time zone, JavaScript will use the browser's time zone.
🌐
W3Schools Blog
w3schools.blog › home › javascript date tutorial
JavaScript Date Tutorial - w3schools.blog
April 21, 2019 - JavaScript Date Tutorial: JavaScript facilitates an object especially to get a day, a month or an year as an output. This object is also called as JavaScript 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.