by Sai gowtham

How to get the current date and time using JavaScript

In this tutorial, we will learn about how to access the current date and time in JavaScript by using Date Object.

Date Object helps us to get the current date and time.

console.log(new Date());

javascript-datetime

Time

We can also access only time by using the new Date().toTimeString() method

console.log(new Date().toTimeString());

JavaScript time

Date

console.log(new Date().toDateString());

js current date

Year

console.log(new Date().getFullYear());

// 2018

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
26,545 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
221,520 students enrolled
44 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
114,575 students enrolled
21 hours of video content
View Course