In Javascript, dates are objects and are inbuilt. There are also methods that can be used to access these date objects, especially when you want to implement these methods in your software using Javascript.
Here are nine (9) Javascript Get date methods you can quickly use:
Get date as a number (1-31):
let date = new Date().getDate()
//21 Get current time (in milliseconds since January 1, 1970)
let time = new Date().getTime(); Get current hour (0-23)
let hours = new Date().getHours(); Get the minute (0-59)
let minutes = new Date().getMinutes() Returns the number of seconds from (0-59)
let seconds = new Date().getSeconds() Returns the weekday as a number (0-6)
let day = new Date().getDay();
let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
console.log(days[day]); Returns the month as a number (0-11)
let month = new Date().getMonth() + 1;
//To get the accurate month we must increment by 1 Returns the year as a four-digit number (yyyy)
let year = new Date().getFullYear();
//2021 Returns the number of milliseconds that has elapsed since January 1, 1970 00:00:00 UTC
let date = new Date()
let now = date.now(); These are the 9 common Javascript Get Date Methods that you can reference in your projects.
See also:
7 Javascript Shortcuts You Should Use in Your Next Project
Latest tech news and coding tips.
1. What Is the Golden Ratio? The Golden Ratio, represented by the Greek letter φ (phi), is…
In CSS, combinators define relationships between selectors. Instead of selecting elements individually, combinators allow you to target elements based…
Below is a comprehensive, beginner-friendly, yet deeply detailed guide to Boolean Algebra, complete with definitions, laws,…
Debugging your own code is hard enough — debugging someone else’s code is a whole…
Git is a free, open-source distributed version control system created by Linus Torvalds.It helps developers: Learn how to…
Bubble Sort is one of the simplest sorting algorithms in computer science. Although it’s not…