Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JavaScript to figure out what day it is?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains how to use JavaScript to figure out what day it is. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use JavaScript to figure out what day it is.

Methods: 1, define the array of "array" ("day", "one", "two", "three", "four", "five", "six"); 2, use the getDay () method of the Date object to obtain the number representing the current week; 3, take the number as the subscript and take the corresponding week value in the array.

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

JavaScript calculates the current day of the week

Get current week / * get current day of the week * * / function getWeekDate () {var weeks = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); var now = new Date (); var day = now.getDay (); var week = weeks [day]; return week } alert (getWeekDate ())

Description:

The getDay () method returns a number that represents the day of the week.

DateObject.getDay ()

DateObject refers to the day of the week, using local time. The return value is an integer between 0 (Sunday) and 6 (Saturday).

So if you need to give the exact day of the week, you need to define an array of Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday").

Then take the number returned by getDay () as the subscript and fetch the corresponding week value from the array.

At this point, I believe you have a deeper understanding of "how to use JavaScript to figure out what day it is today". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report