Software Developer

Display The Current Date on Your Website With JavaScript

This is how to display the current day and date with JavaScript. Since it’s JavaScript, a browser-side language, the date will always be current according to the viewer’s time, anywhere in the world. This code takes the current date from the user’s computer, not from your server.

In addition, this will automatically display in your visitor’s date format. Months and days of the weeks will be automatically translated into the language of the visitor’s browser.

Display Current Date With Spelled-out Month

This example shows the spelled-out month, day, and year, like so:

June 23, 2019

Of course, the month and year will be automatically reversed in countries where that is the standard. For example, in many European countries, this will be displayed as:

23 June 2019

or

23. Juni 2019

new Date().toLocaleDateString(navigator.language, {year: 'numeric', month: 'long', day: 'numeric' });

Display Current Date and Time with Local Timezone Abbreviation

This example shows the spelled-out month, day, year, and local time. The local time will be displayed in local format with the zone abbreviation, like:

June 23, 2019 5:21 PM EDT

var temp = new Date().toLocaleTimeString("default",{timeZoneName:"short"}),
z = temp.split(" ")[2];
if (undefined === z) {
  z = temp.split(" ")[1];
}
new Date().toLocaleDateString("default", {year: 'numeric', month: 'long', day: 'numeric' })
  + ' ' + new Date().toLocaleTimeString("default",{hour:"numeric",minute:"2-digit"}) + ' ' + z;

Display Current Date With Day of the Week and Spelled-out Month

This example also shows the day of the week, along with the month, day, and year, like so:

Sunday, June 23, 2019

Of course, the month and year will be automatically reversed in countries where that is the standard. For example, in European countries, this would be displayed as either:

Sunday 23 June 2019
or
Sonntag, 23. Juni 2019

new Date().toLocaleDateString(navigator.language,{ weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });

Display Current Date in Numerical Format

This example shows the current date in numerical format like:

6/23/2019

This will be automatically adjusted to the current country’s format. For example:

23.6.2019

or

23/06/2019

new Date().toLocaleDateString();

By

We've 2 Responses

  1. September 24th, 2018 at 6:11 pm

    This is really nice. It works well!

    How would I modify this script so that the output was: day Month Year? For example, I need my date to look like this:

    24 September 2018

    avatar

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]