Get the App
SLTechnology News&Howtos  ›  Development  › 

How does JavaScript get what day it is today

Shulou Source: shulou.com Published: 2022-06-02 01:57:52 11月16日 Update

This article mainly explains "how JavaScript gets what day today". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get today's day by JavaScript".

JavaScript method to get today's day: 1, the use of new keywords to define the Date object, the syntax is "new Date ()"; 2, the use of getDay () method through the definition of Date object to get today's day, the syntax is "Date.getDay ()".

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

How does JavaScript get what day it is today?

The Date object is used to process the date and time.

Date objects can be defined by the new keyword. The following code defines a Date object named myDate:

There are four ways to initialize the date:

New Date (); new Date (value); new Date (dateString); new Date (year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]))

The getDay () method returns the number of a day of the week (0,6).

Note: Sunday is 0, Monday is 1, and so on.

The syntax is:

Date.getDay ()

Examples are as follows:

123 Click the button to display today of the week

Tags: Week object method grammar learning key keyword content date and so on code can be passed that is ideas situations buttons tutorials numbers articles ways Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Shulou Information Redmi Apple