JavaScript Code

How to get Current Date and Time using JavaScript?


Problem

get the current date and time from the system in JavaScript

Solution

to get the current date and time from the system in JavaScript, use new Date() constructor. the constructor with no arguments passed returns a string with the current date and time

Program

1. get the current date by creating a Date object using the default constructor

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

Copyright @2022