Working with date and time in JavaScript can be complicated. JavaScript offers us the date handling functionality through a sturdy object, and it is Date. By default, JavaScript will use the browser’s time zone and display a date as the full-text string. The Date object instance represents a single point in time. Despite being named Date, it also handles time. Although, we will not talk about moment.js in this tutorial.

Javascript Date Methods and Objects

Let’s start the article by initializing the Date object.

Date objects are created with a new Date() constructor.

let d = new Date();

The new Date() creates a new date object with the current date and time. Date objects are static and computer time is ticking, but the date objects are not. Now, let’s print the current date and time.

// app.js

let d = new Date();
console.log(d);

Here, I am not running the javascript on the browser, but on the server in the form of Node.js. But the JS methods are the same for both client and server.

#javascript #js #current date and time

Javascript Date Methods and Objects Example Tutorial
1.40 GEEK