Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ JavaScript Date: Get Date methods

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š JavaScript Date: Get Date methods


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

To create and manipulate a particular date, we will have to create a date type object which is a built-in object in JavaScript.

To learn how to create a date type object check the following tutorial:Create Dates in JavaScript

The Date object has many methods that can be classified into different groups: the methods that allow us to obtain a date, those that allow us to define a date, others that allow us to get the current time, etc.

In this tutorial we will go through different methods to get the date, month, year, time, minutes, seconds...So the methods we're going to use are called "getters" because they all start with "get".

getFullYear() Method

Theย getFullYear()ย method returns the complete year of a date.

Image description

getMonth() Method

Theย getMonth()ย method returns the month of a date. This month is returned as a number.

Image description

Here the number of the month returned is 2. It does not mean that the month is February, but 2 represents the month's index.

Because if we were to add all the months from January to December to an array, then the index of January would be 0, and the index of December will be 11.

So here the getMonth() method returned 2 as an index for the month of March.

In general, getMonth() method is used to return the current month.

getDate() Method

Theย getDate()ย method returns the day of a date. The day is returned as a number.

Image description

getHours() Method

Theย getHours()ย method returns the hours of a date. The hours are between 0 and 23.

Image description

getMinutes() Method

The getMinutes()ย method returns the minutes of a date. The minutes are between 0 and 59.

Image description

getSeconds() Method

The getSeconds()ย method returns the seconds of a date. The seconds are also between 0 and 59.

Image description

getDay() Method

Theย getDay()ย method returns the day of a date (day of month or day of week). The day is returned as a number and this number is between 0 and 6.

Image description

The number returned here is 4. 4 refers to Thursday.

If we add all the days of the week to an array like this : ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]

the index 0 will refer to Sunday, and that is because in JavaScript, the first day of the week is Sunday. So index 1 represents Monday, 2 represents Tuesday etc...

getTime() Method

Theย getTime()ย method returns the number of milliseconds since January 1, 1970.

Image description

getUTCFullYear() Method

The getUTCFullYear() returns the complete UTC year of a date. The difference between getFullYear() and getUTCFullYear() methods is around new Year time. If the day date is December 31 or January 1, the return value of getUTCFullYear() and getFullYear() may be different as the getUTCFullYear() returns the Year according to the universal time.

Image description

getUTCMonth() Method

The getUTCMonth() returns the UTC Month.

Image description

getUTCDate() Method

The getUTCDate() returns the UTC Date.

Image description

getUTCDay() Method

The getUTCDay() returns the UTC Day as a number. This number is between 0 and 6.

Image description

The 22nd of December is a Thursday. Here the number returned is 4, and 4 refers to Thursday as explained in the getDay() method.

getUTCHours() Method

The getUTCHours() returns the UTC Hour. If you use getHours() instead getUTCHours() method, you will get the local time that is on your computer. Because getHours() returns the local time.

However if you use the getUTCHours(), you will get the UTC time instead.

The UTC time might be different from the local time due to the time difference.

Image description

So here the UTC time is 3PM while on my computer I have 4 PM. So my time zone is UTC+1.

getUTCMinutes() Method

The getUTCMinutes() returns UTC minutes.

Image description

getUTCSeconds() Method

The getUTCSeconds() returns UTC seconds.

Image description

Conclusion

To retrieve date properties like hours, minutes, seconds, timeโ€ฆ the Date() object allows us to do that through the get methods.

The following get methods get back the local hours, minutes, seconds, day, timeโ€ฆ:

  • getDate()
  • getFullYear()
  • getMonth()
  • getDay()
  • getHours()
  • getMinutes()
  • getSeconds()

The following get methods get back the UTC (Universal time and date) hours, minutes, seconds, day, timeโ€ฆ:

  • getUTCDate()
  • getUTCFullYear()
  • getUTCMonth()
  • getUTCDay()
  • getUTCHours()
  • getUTCMinutes()
  • getUTCSeconds()

Read More

JavaScript Date: Create Dates in JavaScript

5 ways to declare a function in JavaScript

How to loop through an array in JavaScript?

Understanding JavaScript Objects: From Basic Concepts to Practical Usage

Object constructor functions: How does the Javascript constructor work?

Fetch API: Send data from front-end to back-end

...



๐Ÿ“Œ JavaScript Date: Get Date methods


๐Ÿ“ˆ 41.55 Punkte

๐Ÿ“Œ Exploring JavaScript Date Object Methods: A Comprehensive Guide


๐Ÿ“ˆ 27.63 Punkte

๐Ÿ“Œ JavaScript console methods for better debugging - ๐Ÿ”ฎ Unlocking JavaScript Magic


๐Ÿ“ˆ 26.58 Punkte

๐Ÿ“Œ How to add days to date and get new date on Linux


๐Ÿ“ˆ 22.43 Punkte

๐Ÿ“Œ Get Yesterday Date in JavaScript


๐Ÿ“ˆ 21.38 Punkte

๐Ÿ“Œ Adobe Acrobat Reader up to 7.0.8 Javascript Methods cross site scripting


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Learn the JavaScript Array.every() and Array.some() methods


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ The Javascript higher order array methods with reactjs examples


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ 20 JavaScript: Array Methods


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript Array Methods: Understand By Implementing


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript Tutorial Series: String methods


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript Console Methods: Beyond console.log()


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript String Tutorial โ€“ String Methods in JS


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Adobe Acrobat Reader up to 8.1.2 Javascript Methods memory corruption


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ The Missing Math Methods in JavaScript


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ What is difference between JSON.parse() and JSON.stringify() Methods in JavaScript ?


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript Array Methods Cheatsheet


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Different Methods to Round Float Numbers in JavaScript?


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ filter vs. find: JavaScript Array Methods


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript Array Tutorial โ€“ Array Methods in JS


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ ๐Ÿ“š 34 JavaScript String Methods Cheatsheet


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ 12 JavaScript Number Methods Cheatsheet


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Summary of Common Javascript Array Methods


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ 13 Most Common JavaScript String Methods You Should Know About


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript's Grouping Methods: Object.groupBy and Map.groupBy ๐Ÿคฏ


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ 17 JavaScript Array Methods Everyone Needs to Know


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Understanding the Map, Filter & Reduce Methods in JavaScript


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ ECMAScript 2023 Spec for JavaScript Includes New Methods for Arrays


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ All the new javascript array methods you missed in 2023


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Mastering JavaScript: A Comprehensive Guide to Essential Methods and Latest Features


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Mastering data with 7 new JavaScript Set methods


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript Array Methods: A Comprehensive Guide


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ JavaScript Array Methods: Map vs Filter vs Redux


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ How to Compare Two Dates in JavaScript โ€“ Techniques, Methods, and Best Practices


๐Ÿ“ˆ 19.12 Punkte

๐Ÿ“Œ Essential JavaScript ES6 Methods Every Developer Should Know


๐Ÿ“ˆ 19.12 Punkte











matomo