Introduction

Whether you are creating a daily routine app, your own blog, or most any other type of dynamic web app, you will probably need to work with dates. In this article, we’re going to learn how to get the current date in JavaScript, so you can successfully develop your applications. In JavaScript, there is a plethora of options to choose from, but the main class being used is Date(). It has a lot of methods and how you use it will depend on the format of the date you want to get. Afterwards, I will show you a popular JavaScript library that can be used for formatting time in general, and not just dates.

Using the Date() class

So as I previously mentioned, Date() is a go-to class in JavaScript when talking about time. There are a couple of approaches to this:

  • Using getDate, getMonth, and getFullYear methods
  • Using toJson method
  • Using toISOString, toUTCString and toLocaleDateString methods
  • Using now method

#javascript

How to Get the Current Date in JavaScript
4.15 GEEK